I have a select issue with my members, my database structure is below User has many shops Shop belongs to a membership Shop has many items For front page I want to show items where membership of the shop has ad_enabled and this is what I have in mind but it returns with "Association named ''membership'' was not found; perhaps you misspelled it?" I tried to add to Item class belongs_to :membership And added Membership Class following has_many :items, :through => :shops but helaas not working. Any suggestion how to handle this situation? Thanks in advance class Item <.... def self.find_by_ad_enabled(options={}) ad_enabled do self.find :all, {:order => "RAND()"}.merge(options) end end protected def self.ad_enabled with_scope(:find => {:conditions => ''memberships.ad_enabled = 1 and shops.expires_on >= NOW() and shops.enabled = 1'', :include => [:shop, :images, :membership]}) do yield end end end create_table "items", :force => true do |t| t.column "shop_id", :integer .... end create_table "shops", :force => true do |t| t.column "user_id", :integer, :default => 0, :null => false t.column "membership_id", :integer t.column "expires_on", :date t.column "enabled", :boolean, :default => true .... end create_table "users", :force => true do |t| ..... end create_table "memberships", :force => true do |t| t.column "ad_enabled", :boolean, :default => false .... end -- 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 -~----------~----~----~----~------~----~------~--~---