Forum: Ruby on Rails Problem with sum and include

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1843b506d589247217d2d1e85add8336?d=identicon&s=25 Tony Buser (gr0k)
on 2007-03-06 22:01
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?
This topic is locked and can not be replied to.