This project is archived and is in readonly mode.
ActiveRelation bug; size() returning incorrect value with limit().
-
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
-
James Harton
Ahh right! I understand. You don't think this is a little counter-intuitive?
-
José Valim
- Assigned user set to Emilio Tagua
-
Emilio Tagua
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...
-
James Harton
Wow, thanks!
-
Repository
- State changed from new to resolved
(from [5441e082f9478ddb3c676c681b09786f1391483c]) Add tests for relation count. Fix other tests that were conceptually wrong.
[#4882 ActiveRelation bug; size() returning incorrect value with limit(). state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/5441e082f9478ddb3c676c681b0978...
