I've implemented the following scope in a rails 3 application:

    scope :popular, lambda { |l = 5| order('views desc').limit(l) }

However, it seems that when you attempt to count its records directly
it doesn't apply the scope filters.

For example:

    Post.popular.size #=> 20

Checking the log, it executes the following query:

    SQL (0.4ms)  SELECT COUNT(*) AS count_id FROM `posts` LIMIT 5

Now if I execute

    Post.popular.all.size #=> 5

And the correct query is executed:

    Post Load (1.5ms)  SELECT `posts`.* FROM `posts` ORDER BY views
desc LIMIT 5

Anyone else experienced this kind of behavior? If so, any idea if this
is the expected behavior or am I facing a bug?

Best regards,
DBA

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-c...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to