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

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!!