Translate my query for my dependentdropdown

I have here professor, subject, and specialization. professor and specialization has many to many relationship the bridge table is professor_specialization. subject and specialization has many to many relationship bridge table is subject_specialization.

I need it for my dependent dropdown in professor, the dropdown will list all professor that has the same specialization in subject.

Here is my query. I need it to translate this for yii. I’m new in Yii pls someone translate this.

This query will generate all professors and subjects that has the same specialization.


from professor, specialization, professor_specialization, subject, subject_specialization

where = professor_specialization.professor_id

and professor_specialization.specialization_id =

and = subject_specialization.specialization_id

and subject_specialization.subject_id =

Should I add it up here in my relation?

Professor model relation

'specializations'=>array(self::MANY_MANY, 'Specialization',

                'professor_specialization(professor_id, specialization_id)')

Subject model relation

'specializations'=>array(self::MANY_MANY, 'Specialization',

                'subject_specialization(subject_id, specialization_id)')

How can I combine it? Please Help me…

Not sure I completely understand the problem domain, but I assume there is a Specialization model. Try adding the relationship ‘subjects’ to that model. Then the query may look similar to this

$models = Professor::model()

  ->with('specializations', 'specializations.subjects')




I don’t know if this will work with MANY_TO_MANY relationships, though.

(not tested)


Professor::model()->with('specializations','specializations.subjects')->findAll('subject_id=:subject', array(':subject'=>(int) $_POST['Schedule']['subject_id']));

This will help a lot in my school project enrollment system, I never tried to use combining relations with “.” It took me more than a day figuring out how to do it. I’m such a noob :lol: :lol:

Thank you so much! ;D