Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

named_scope drops :limit option

#317

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

Reported by Tekin · June 4th, 2008 @ 01:09 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Tekin
    Tekin

    Here's a failing test

    June 3rd, 2008 @ 03:24 PM

  2. Tekin
    Tekin

    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.

    June 4th, 2008 @ 04:14 PM

  3. Tekin
    Tekin

    OK, my mistake, to get the desired effect, you have to do:

    Product.most_ordered.all(:limit => 3)

    invalid ticket...

    June 5th, 2008 @ 01:38 PM

  4. Pratik
    Pratik
    • State changed from new to invalid
    • Tag set to activerecord, bug, named_scope, tested

    July 23rd, 2008 @ 03:05 PM