如何将“自然联接”转换为yii2 Active查询?

时间:2019-10-26 16:42:11

标签: php mysql yii2 relational-database

如何在yii2中将该查询转换为ActiveQuery?

SELECT * from table1 natural join table2 natural join table3

1 个答案:

答案 0 :(得分:1)

假设表Table1与模型类Model1相关联,并且自然连接的列名为id

     $model =  Model1::find()
      ->innerJoin('Table2', 'table1.id = Table2.id' )
      ->innerJoin('Table3', 'table1.id = Table3.id' )
      ->all();