Reputation: 2207
Could not find any examples on how to do this, but im building a query where it can happen that the column is empty, if empty skip this row.
It should skip when the translation does not have any value(is empty)
$query = (new \yii\db\Query())
->select(['a.id',
'b.filter_item_id',
'c.id as fid',
'c.filter_id',
'd.translation'//skip when this has no value
])
->from(['a' => 'product'])
->leftJoin( ['b' => 'product_filter_item'] ,
'b.product_id = a.id ')
->leftJoin( ['c' => 'filter_item'] ,
'c.filter_id = b.filter_item_id ')
->leftJoin( ['d' => 'filter_item_translation'] ,
'd.filter_item_id = c.id AND d.attribute = "name" AND
d.language = "en"')
->all();
Upvotes: 0
Views: 378
Reputation: 23788
You can add in on condition into the join
for filter_item_translation
$query = (new \yii\db\Query())
->select(['a.id',
'b.filter_item_id',
'c.id as fid',
'c.filter_id',
'd.translation'//skip when this has no value
])
->from(['a' => 'product'])
->leftJoin( ['b' => 'product_filter_item'] ,
'b.product_id = a.id ')
->leftJoin( ['c' => 'filter_item'] ,
'c.filter_id = b.filter_item_id ')
->leftJoin( ['d' => 'filter_item_translation'] ,
'd.filter_item_id = c.id AND d.attribute = "name" AND
d.language = "en" and d.translation != ""')
->all();
Upvotes: 0