In my Rails 3.2 app, there is an attended_university model with fields university_name,major_name,university_type(0 for undergrad and 1 for graduate) and advisor_id and advisor model. Advisor has many attended_universities and attended_university belongs to advisor.
I wanna get the advisors whose undergrad is major1, university1 and graduate is major2 and university2:
Advisor.includes(:attended_universities)
.where("attended_universities.university_name = 'university1' AND attended_universities.major_name = 'major1' AND attended_universities.university_type = 0")
.where("attended_universities.university_name = 'university2' AND attended_universities.major_name = 'major2' AND attended_universities.university_type = 1")
But it gives empty result which shouldn't. Wondering what the right way to do this is.
Aucun commentaire:
Enregistrer un commentaire