Im working on getting data from a database, in this case from 3 tables, ‘product’ is used to check if the product is deleted or enabled, if the product is not deleted and is enabled than the ‘product_translation’ is used to get the language , translation & product_id (this is used to group the data with ArrayHelper::index) this goes well(see code below), but I now need to get data from a third table (in this case a category) which has a translation field which we want to to add to the data output, this field must match the following ways the category_id, attribute & language fields must match all. I hope that somebody understands this.
Im new to yii2 so I still are figuring out how to use this all.
----------------------------------------------
| product |
----------------------------------------------
| id | is_deleted | is_enabeld | category_id |
----------------------------------------------
---------------------------------------------------
| product_translation |
---------------------------------------------------
| product_id | attribute | language | translation |
---------------------------------------------------
----------------------------------------------------
| category_translation |
----------------------------------------------------
| category_id | attribute | language | translation |
----------------------------------------------------
Used WORKING query until now:
$query = new Query;
$slugs = $query->select('cbt.language, cbt.translation, cbt.product_id')
->from(['cbt'=>'product_translation'])
->leftJoin(['cb'=>'product', 'cbx' => 'category_translation'], 'cb.id=cbt.product_id')
->where(['cb.is_deleted' => 0,
'cb.is_enabled' => 1,
'cbt.attribute' => 'slug'
])
->all();
// Group values by id.
$results = ArrayHelper::index( $slugs , null , 'product_id' );