This project is archived and is in readonly mode.
named_scope drops :limit option
Reported by Tekin | June 4th, 2008 @ 01:09 PM
Passing the :limit option to a named scope has no affect on the query generated.
e.g.
class Product
named_scope :most_ordered, :order => 'ordered_count DESC'
end
# We want the three most ordered products
Product.most_ordered(:limit => 3)
Generates the following sql:
SELECT * FROM `products` ORDER BY ordered_count DESC
Comments and changes to this ticket
-
Tekin June 4th, 2008 @ 04:14 PM
I've just noticed that you can use .first to get a subset of results, but this does not limit at the database level:
Product.most_ordered.first(3)
will hit the dabase for all products before returning the first three.
-
Tekin June 5th, 2008 @ 01:38 PM
OK, my mistake, to get the desired effect, you have to do:
Product.most_ordered.all(:limit => 3)
invalid ticket...
-
Pratik July 23rd, 2008 @ 03:05 PM
- State changed from new to invalid
- Tag set to activerecord, bug, named_scope, tested
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>