我有一个 QuestionCategory 模型,他有很多问题。
当我执行此查询时,@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 questions.* FROM questions WHERE questions.questions_category_id = 2AND MY CONDITIONS
可能的?欢呼队友