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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Thu, May 2, 2013 at 1:00 PM, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a join table "galleries_questions".I''ll hope that''s really ''galleries_pictures'' :-)> 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).picturesNot relevant, but @gallery.pictures would work there... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Thu, May 2, 2013 at 6:07 PM, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: If you don''t top-post, this will be easier :-)> class Gallery < ActiveRecord::Base > has_and_belongs_to_many :pictures > > class Picture < ActiveRecord::Base > has_and_belongs_to_many :galleriesWhat 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'' -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.