Answer the question
In order to leave comments, you need to log in
How to make connections through trhough in Yii for 4 tables?
I struggled for half a day) I understand that you can make a SQL query. And I wrote it:
SELECT
DISTINCT pavT.name
FROM
Buildings AS b
JOIN Pavilions AS p ON p.building_id = b.id
JOIN PavilionsTypes AS pt ON p.id = pt.pavilion_id
JOIN PavTypes AS pavT ON pt.type_id = pavT.id
AND b.id = 1
class Buildings extends CActiveRecord
{
public function relations()
{
return array(
'pavilions' => array(self::HAS_MANY, 'Pavilions', 'building_id'), //тут все очевидно
'actualPavTypes' => array(self::HAS_MANY, 'PavTypes', 'building_id', 'through' => 'pavilions'),
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question