I do this:
check1 = inquiries.select("question_id").where(:membership_id => self.id)
This returny a active Record array with entries like this:
#<ActiveRecord::AssociationRelation [#<Inquiry id: nil, question_id: 21113>,
Now I want to select in a secon query all questions which are not in the inqueries
Tried this:
lesson.questions.where("NOT IN ?",check1)
But that does not work, probably because the first query returns an active record array with 2 values for each object?
how could look like a solution?
Make use of pluck
check1 = inquiries.where(membership_id: self.id).pluck(:question_id)
#=> [1, 2, 3] # List of ids
lesson.questions.where("id NOT IN (?)", check1)
# OR
lesson.questions.where.not(id: check1)
NOTE: If you have an association between lesson and inquiries you can make use of joins and get the result in one query itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With