Forum: Ruby on Rails has_many.count not accepting options hash

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.
89441a6c74647d292f5cc951eae24cfa?d=identicon&s=25 Jack Christensen (Guest)
on 2006-04-20 17:51
(Received via mailing list)
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:in `execute'
        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:in `select_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:in `execute_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:in `count'
        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 Christensen
jackc@hylesanderson.edu
89441a6c74647d292f5cc951eae24cfa?d=identicon&s=25 Jack Christensen (Guest)
on 2006-04-23 03:11
(Received via mailing list)
I suppose I should check edge rails a little more often. This was fixed
on 4/19/06 in Changeset 4237.

Thanks.

Jack Christensen 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 Christensen
jackc@hylesanderson.edu
This topic is locked and can not be replied to.