Join table query question

Hi, I'm a novice and could use help with a join table question. I have
a join table "galleries_questions".

I can't figure out how to query it for pictures in a selected gallery.

Controller:
@gallery = Gallery.where("minisection_id" =>
session[:minisection_id]).first
@pictures = Gallery.find(@gallery).pictures

View:
<% @pictures.each do |picture| %>
          <%= image_tag picture.image_url.to_s %>

ERROR:
PGError: ERROR: column pictures.gallery_id does not exist
LINE 1: SELECT "pictures".* FROM "pictures" WHERE "pictures"."galle...
                                                   ^
: SELECT "pictures".* FROM "pictures" WHERE "pictures"."gallery_id" =
11

Any suggestions?

Thanks

I have a join table "galleries_questions".

I'll hope that's really 'galleries_pictures' :slight_smile:

I can't figure out how to query it for pictures in a selected gallery.

How do you have the relationship defined in the models?

Controller:
@gallery = Gallery.where("minisection_id" =>
session[:minisection_id]).first
@pictures = Gallery.find(@gallery).pictures

Not relevant, but @gallery.pictures would work there...

Yes, its actually 'galleries_pictures'

class Gallery < ActiveRecord::Base
  has_and_belongs_to_many :pictures

class Picture < ActiveRecord::Base
  has_and_belongs_to_many :galleries

"Not relevant, but @gallery.pictures would work there..." Where?

If you don't top-post, this will be easier :slight_smile:

class Gallery < ActiveRecord::Base
  has_and_belongs_to_many :pictures

class Picture < ActiveRecord::Base
  has_and_belongs_to_many :galleries

What does the migration for the creation of your join table look like?

"Not relevant, but @gallery.pictures would work there..." Where?

replacing '@pictures = Gallery.find(@gallery).pictures'