You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for example I have three tables. order , item , order_item
Class Order extends ActiveRecord
{
public function getItems()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->viaTable('order_item', ['order_id' => 'id']);
}
}
Order::findOne(1)
The querys
1.select * from order where id=1;
2.select * from order_item where order_id = 1;(empty result)
3.select * from item where 0=1; (why have this? );
I looked the source code
3.select * from item where 0=1; (why have this? );
the condition in where could be much more complex than in your case, it is not easily possible for Yii to figure out whether a query result will be empty, so we build a query and let the database decide.
It might be possible to optimize this in some way though.
Activity
cebe commentedon Nov 2, 2018
the condition in where could be much more complex than in your case, it is not easily possible for Yii to figure out whether a query result will be empty, so we build a query and let the database decide.
It might be possible to optimize this in some way though.
rob006 commentedon Nov 3, 2018
Can you check this with last version of Yii? In 2.0.11 support for
emulateExecutionwas added, which should avoid such dummy queries.