problem with built-in named scope all

Hello,

I'm having a problem with the built-in all scope. For example in my Subscription model,

Subscription.all.count

NoMethodError: undefined method `count' for #<Array:0xb5dce7f8>         from (irb):46

However, my own version of all defined in the model simply as "named_scope :everything" works fine

Subscription.everything.count

=> 849

I also cannot chain scopes onto all

Subscription.all.active.count

NoMethodError: undefined method `active' for #<Array:0xb5a80268>         from (irb):50

But

Subscription.everything.active.count

=> 611

I'm relatively new to Rails so any insights people can give would be greatly appreciated. Thanks!

My environment is

[root@localhost trunk]# gem -v 1.1.1 [root@localhost trunk]# gem list

*** LOCAL GEMS ***

actionmailer (2.1.0) actionpack (2.1.0) activerecord (2.1.0) activeresource (2.1.0) activesupport (2.1.0) mysql (2.7) piston (1.4.0) rails (2.1.0) rake (0.8.1) [root@localhost trunk]# cat /etc/issue CentOS release 5.2 (Final) Kernel \r on an \m [root@localhost trunk]# uname -a Linux localhost.localdomain 2.6.18-92.1.6.el5 #1 SMP Wed Jun 25 13:49:24 EDT 2008 i686 i686 i386 GNU/Linux

Since .all internally is doing a find(:all), it's returning an array, not an proxy like named_scope and the association methods do. So although it might look like a named scope, it actually isn't.

So instead of Subscription.all.count, you have to do Subscription.count. Instead of Subscription.all.active.count, just do Subscription.active.count. Having the "all" in there is redundant anyway, although I sympathize with the concept that it might feel more consistent that way.

Jeff purpleworkshops.com