Monday, 15 June 2015

sql - Pass conditions to subqueries - rails activerecords -



sql - Pass conditions to subqueries - rails activerecords -

i have questioncategory model hasmany question.

when query @quizzs = questionscategory.find(:all) ok. it's querying catégories , associated questions:

questionscategory load (0.2ms) select `questions_categories`.* `questions_categories` question load (0.3ms) select `questions`.* `questions` `questions`.`questions_category_id` = 1 question load (0.4ms) select `questions`.* `questions` `questions`.`questions_category_id` = 2 question load (0.3ms) select `questions`.* `questions` `questions`.`questions_category_id` = 3

but, i'd pass status questions subqueries. @quizzs = questionscategory.find(:all, :questions => [ :conditions => {my conditions} ])

and subqueries looking this:

select questions.* questions questions.questions_category_id = 2 and conditions

possible? cheers mates

to result sql ( select questions.* questions questions.questions_category_id = 2 , conditions) can follows:

quetionscategory.find(2).questions.all(:conditions => [your conditions])

sql ruby-on-rails rails-activerecord

No comments:

Post a Comment