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.

ActiveRelation bug; size() returning incorrect value with limit().

#4882

Easiest to explain with a snippet:

Loading development environment (Rails 3.0.0.beta4)
ruby-1.8.7-p249 > Post.limit(20).size
 => 1000 
ruby-1.8.7-p249 > Post.limit(20).all.size
 => 20

Reported by James Harton · June 17th, 2010 @ 01:34 AM

State: resolved
Milestone: none
Assigned to: Emilio Tagua Emilio Tagua
Importance: Low

Activity

  1. PacoGuzman
    PacoGuzman

    When you're executing:

    Post.limit(20).size

    In the database the following sql query is executed:

    SELECT COUNT(*) AS count_id FROM posts LIMIT 20;

    And with that query the 'LIMIT' options isn't applied to the database. But in the other case we got:

    Post.limit(20).all.size => SELECT * FROM posts LIMIT 20;

    And the answer for the size of the array returned. So IMHO there isn't any problem with ActivceRelation

    June 20th, 2010 @ 05:32 PM

  2. James Harton
    James Harton

    Ahh right! I understand. You don't think this is a little counter-intuitive?

    June 20th, 2010 @ 09:43 PM

  3. José Valim
    José Valim
    • Assigned user set to Emilio Tagua

    June 22nd, 2010 @ 05:03 PM

  4. Emilio Tagua
  5. James Harton
  6. Repository
    Repository
    • State changed from new to resolved

    June 24th, 2010 @ 11:14 AM