Given these models: class Intranet < ActiveRecord::Base has_many :matters has_many :bills end class Matter < ActiveRecord::Base has_many :bills belongs_to :intranet end class Bill < Entry belongs_to :intranet belongs_to :matter end These three queries work: Bill.count(:include => :matter, :conditions => ["matters.number=10711"]) Bill.sum(:amount, :include => :matter, :conditions => ["matters.number=10711"]) Intranet.find(1).bills.sum(:amount, :include => :matter, :conditions => ["matters.number=10711"]) However, this does not work: Intranet.find(1).bills.count(:include => :matter, :conditions => ["matters.number=10711"]) ActiveRecord::StatementInvalid: Mysql::Error: Unknown table ''matters'' in where clause: SELECT count(*) AS count_all FROM entries WHERE (entries.intranet_id = 1 AND (matters.number=10711)) AND ( (entries.`type` = ''Bill'' ) ) It''s ignoring the include. Am I doing something wrong or is this a bug? -- 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 -~----------~----~----~----~------~----~------~--~---