Rails request not in formatting formatting
I'm doing it:
check1 = inquiries.select("question_id").where(:membership_id => self.id)
Returns an active array of records with the following elements:
#<ActiveRecord::AssociationRelation [#<Inquiry id: nil, question_id: 21113>,
Now I want to select in the secon request all questions that are not in requests
Tried this:
lesson.questions.where("NOT IN ?",check1)
But it doesn't work, perhaps because the first query returns an active array of records with 2 values ββfor each object?
what the solution might look like?
+3
source to share
2 answers
Use 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. ... Once you have a link between a tutorial and queries, you can use joins
and get the result in one query.
+3
source to share