Query through a join table question


I am trying to do the following database query (ie find all question
id’s with the selected minisection id):

minisection_questions = Question.where(minisection_id:

I have a question table, a minisection table, and a
minisections_questions join table.

Question model - has_and_belongs_to_many :minisections
Minisection model - has_and_belongs_to_many :questions

I get the following error:
PGError: ERROR: column questions.minisection_id does not exist
LINE 1: SELECT id FROM “questions” WHERE “questions”."minisection_i…
: SELECT id FROM “questions” WHERE “questions”.“minisection_id” = 2

Also tried minisection_questions =
minisection_id).pluck(:id) and got the folowing:

error:undefined local variable or method `question’ for



Try Minisection.find(minisection_id).questions.pluck(:id)

Ganesh Ranganathan wrote in post #1138274:

Try Minisection.find(minisection_id).questions.pluck(:id)

That did it! Thanks!!


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs