This project is archived and is in readonly mode.
ActiveRelation bug; size() returning incorrect value with limit().
Reported by James Harton | June 17th, 2010 @ 01:34 AM
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
Comments and changes to this ticket
-
PacoGuzman June 20th, 2010 @ 05:32 PM
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
-
James Harton June 20th, 2010 @ 09:43 PM
Ahh right! I understand. You don't think this is a little counter-intuitive?
-
José Valim June 22nd, 2010 @ 05:03 PM
- Assigned user set to Emilio Tagua
-
Emilio Tagua June 23rd, 2010 @ 06:10 PM
Hey,
I've fixed this in Arel. I attach patch with tests for AR.
Arel commits:
http://github.com/rails/arel/commit/71e92992e66f461acaabc3ac2f3ec64...
and
http://github.com/rails/arel/commit/a040b1c0e68f7a5145a6decf6731be9...
-
Repository June 24th, 2010 @ 11:14 AM
- State changed from new to resolved
(from [5441e082f9478ddb3c676c681b09786f1391483c]) Add tests for relation count. Fix other tests that were conceptually wrong.
[#4882 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/5441e082f9478ddb3c676c681b0978...
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>
People watching this ticket
Attachments
Referenced by
- 4882 ActiveRelation bug; size() returning incorrect value with limit(). [#4882 state:resolved]
- 5829 ActiveRecord::Relation#empty? fails for grouped relations, as OrderedHash is missing #zero? Not to speak of other problems with using count() on your...