我有一個QuestionCategory模型,他有許多問題。將條件傳遞給子查詢 - rails activerecords
當我做這個查詢@quizzs = QuestionsCategory.find(:all)
一切都很好。它查詢所有的分類和相關的問題:
QuestionsCategory Load (0.2ms) SELECT `questions_categories`.* FROM `questions_categories`
Question Load (0.3ms) SELECT `questions`.* FROM `questions` WHERE `questions`.`questions_category_id` = 1
Question Load (0.4ms) SELECT `questions`.* FROM `questions` WHERE `questions`.`questions_category_id` = 2
Question Load (0.3ms) SELECT `questions`.* FROM `questions` WHERE `questions`.`questions_category_id` = 3
但是,我想通過一個條件的問題子查詢。像 @quizzs = QuestionsCategory.find(:all, :questions => [ :conditions => {MY CONDITIONS} ])
然後得到的東西的子查詢看起來像這樣:
SELECT問題* FROM問題WHERE questions.questions_category_id = 2 AND MY CONDITIONS
可能? 乾杯隊友
你使用導軌2或3? – jvnill 2013-02-21 14:52:37