0
我有三個表skill_development,training_programs和參與者。 skills_development有許多training_programs,training_programs有許多參與者。 training_programs也有不同的類別A-F,參與者有不同的性別。Ruby SQL查詢相關屬性
我希望能夠訪問屬於女性且屬於培訓計劃A-C的技能發展中的所有參與者。
有沒有辦法用單個查詢來做到這一點?
我可以做
tp = @skills_development.training_programs.where("category = ?", "A")
得到所有A類
p = @skill_development.participants.where("gender = ?", "female")
的培訓計劃和所有女性參與者
但如何搭配這些一起炒我的大腦。我想你可能只是
tp = @skills_development.training_programs.where("category = ?", "A")
tp.participants.where("gender = ?", "female")
,但我得到
NoMethodError: undefined method `participant' for #<ActiveRecord::Relation:0x007fc7e6bcdaa8>
什麼想法?
感謝的人那是什麼,我需要感謝的參考! – TheLegend