# Model.count broken by Rails 2.0.x

**URL:** <https://www.ruby-forum.com/t/model-count-broken-by-rails-2-0-x/137259>\
**Category:** Rails\
**Created:** [May 10, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/model-count-broken-by-rails-2-0-x/137259 "2008-05-10T22:34:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [May 10, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/model-count-broken-by-rails-2-0-x/137259/1 "2008-05-10T22:34:11Z")

</div>

Have a working 1.2.6 application (OS X 10.4.11, Ruby 1.8.6), which I am  
now trying to run under 2.0.2 (via freeze).

First snag I’ve run into that I can’t find any info on is that Rails is  
gagging on a simple .count statement like this:

(Comment.count [“article\_id = ?”, (session[:selected\_article])])

It would appear that the ? is not be substituted with a quoted value.  
Rails generates a query that looks like this …article\_id = ?12345…  
instead of this …article\_id = ‘12345’…

Is this a known bug, a deprecated feature, or syntax error in my code  
I’ve managed to get away with so far?

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [May 10, 2008, 11:12pm UTC](https://www.ruby-forum.com/t/model-count-broken-by-rails-2-0-x/137259/2 "2008-05-10T23:12:54Z")

</div>

On May 10, 2008, at 1:34 PM, Greg W. wrote:

> It would appear that the ? is not be substituted with a quoted value.  
> Rails generates a query that looks like this …article\_id = ?12345…  
> instead of this …article\_id = ‘12345’…
> 
> Is this a known bug, a deprecated feature, or syntax error in my code  
> I’ve managed to get away with so far?

OK, yes, I found that it is deprecated, but that means it should  
still work?

Anyway, updating the code to a full :conditions syntax works:

(Comment.count(:conditions =\> [“article\_id = ?”, session  
[:selected\_article]]))

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [May 10, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/model-count-broken-by-rails-2-0-x/137259/3 "2008-05-10T23:15:14Z")

</div>

On Sat, May 10, 2008 at 6:12 PM, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> OK, yes, I found that it is deprecated, but that means it should  
> still work?
> 
> Anyway, updating the code to a full :conditions syntax works:
> 
> (Comment.count(:conditions =\> [“article\_id = ?”, session  
> [:selected\_article]]))

As far as can I remember, the deprecation warning tells you that this  
feature will be removed on rails 2 🙂

–  
Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) |  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) (en)  
João Pessoa, PB, +55 83 8867-7208
