So I have this structure. class Gallery < ActiveRecord::Base belongs_to :owner, :polymorphic => true has_many :folders, :order => ''slug'', :dependent => :destroy class Folder < ActiveRecord::Base has_many :photos, :dependent => :destroy, :conditions => "parent_id IS NULL" belongs_to :gallery class User < ActiveRecord::Base has_one :gallery, :as => :owner, :dependent => :destroy has_many :folders, :through => :gallery Seems fine, right? So @user.folders should do join between users, galleries and folders. users.id (1 in the example) == gallery.owner_id and gallery.id =folders.gallery_id Right? Well it does not. Mysql::Error: #42S22Unknown column ''galleries.gallery_id'' in ''on clause'': SELECT folders.* FROM folders INNER JOIN galleries ON folders.id = galleries.gallery_id WHERE ((galleries.owner_id = 1) AND (galleries.owner_type = ''User'')) This query doesn''t make a lot of sense for me... Anyone wanna explain? -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---