Im trying to get data from a DB, but I ran into an little issue, as im trying to get data from table ‘product_translation’ which has a column called ‘attribute’ which as 2 values (name & description) and a column ‘translation’ where the value is that I need, when using the query below it will return the results double.
| product_id | attribute | translation | language |
--------------------------------------------------------------
| 1 | name | some name | de |
--------------------------------------------------------------
| 2 | description | lorem ipsum dolor | de |
--------------------------------------------------------------
more
$query = (new \yii\db\Query())
->select(['a.id', 'a.api_id', 'a.api_name' , 'b.translation as name' , 'c.translation as description'])
->from(['a' => 'product'])
->leftJoin( ['b' => 'product_translation'] ,
'b.product_id = a.id AND b.attribute = "name" AND b.language = "de"')
->leftJoin( ['c' => 'product_translation'] ,
'c.product_id = a.id AND c.attribute = "description" AND b.language = "de"')
->all();