cesar.yii
(Cesarfpmx)
1
I have this table:
business(id, id_head_office)
and I want to execute this query in yii:
select * from business where id_head_office = id;
using ActiveRecords methods. I tried these:
$head_offices = Business::find()
->where(['id_head_office' => 'id'])
->all();
$head_offices = Business::findAll([
'id_head_office' => 'id',
]);
But I don’t get the correct result.
Why? Thanks in advance 
softark
(Softark)
2
‘id’ is treated as a string here.
[sql]
select * from business
where id_head_office
= "id";
[/sql]
http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail
$head_offices = Business::find()
->where(new Expression('id_head_office = id'))
->all();
http://www.yiiframework.com/doc-2.0/yii-db-expression.html