Has_many.count not accepting options hash


#1

has_many.count does not seem to support an options hash like
ActiveRecord::Base.count does.

Example:

AcademicProgram.find(:first).course_requirements.count :conditions
=> “courses.name LIKE ‘a%’”, :include => :course
=> 40

ap.ap_requirements.count :conditions => “courses.name LIKE ‘a%’”,
:include => :course
ActiveRecord::StatementInvalid: Mysql::Error: #42000You have an error in
your SQ
L syntax; check the manual that corresponds to your MySQL server version
for the
right syntax to use near ‘includecourse))’ at line 1: SELECT count(*)
AS count_
all FROM ap_requirements WHERE (ap_requirements.academic_program_id = 1
AND (con
ditionscourses.name LIKE ‘a%‘includecourse))
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor
d/connection_adapters/abstract_adapter.rb:120:in log' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor d/connection_adapters/mysql_adapter.rb:185:inexecute’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor
d/connection_adapters/mysql_adapter.rb:337:in select' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor d/connection_adapters/mysql_adapter.rb:180:inselect_one’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor
d/connection_adapters/abstract/database_statements.rb:16:in
select_value' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor d/calculations.rb:161:inexecute_simple_calculation’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor
d/calculations.rb:141:in calculate' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor d/calculations.rb:64:incount’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor
d/associations/has_many_association.rb:47:in `count’
from (irb):21

It appears to call to_s on whatever is passed to it.

Is this a bug, normal behavior, or am I doing something wrong?

Thanks.


Jack C.
removed_email_address@domain.invalid


#2

I suppose I should check edge rails a little more often. This was fixed
on 4/19/06 in Changeset 4237.

Thanks.

Jack C. wrote:

in your SQ
from
d/connection_adapters/abstract/database_statements.rb:16:in
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_recor
d/associations/has_many_association.rb:47:in `count’
from (irb):21

It appears to call to_s on whatever is passed to it.

Is this a bug, normal behavior, or am I doing something wrong?

Thanks.


Jack C.
removed_email_address@domain.invalid