This project is archived and is in readonly mode.
ModelName.limit(n).size returns invalid number
-
Stevo
Still, isn't it counter-intuitive that size() executed on scope counts all records disregarding limit() condition?
-
lakshmanan
size() - returns the count of all the records in the table if the ActiveRecord::Relation is not loaded. thats why you got 200 (the count)
see http://github.com/rails/rails/blob/master/activerecord/lib/active_r... line 81
# in rails source code def size loaded? ? @records.length : count end -
lakshmanan
- Tag changed from limit rails3 arel, scope to limit rails3 arel, invalid, scope
-
Manik
- Assigned user set to Pratik
Lazy loading might be causing some issue with the first call
Question.limit(3).all.size should return what you need. [Not sure though why anybody would want to call that]
Not sure why length works correctly.
-
Stevo
I just did want to make myself sure, that there was at least n records returned (in example that I gave it doesn't make sense, however there were more scopes in original code)
-
Rohit Arondekar
- Assigned user cleared.
- Tag changed from limit rails3 arel, invalid, scope to limit rails3 arel, scope
- Importance changed from to Low
Stevo, did you try this on Rails master? It works fine for me on master:
Post.all.size => 4 Post.all.length => 4 Post.limit(3).size => 3 Post.limit(3).length => 3 -
Stevo
rails -v
Rails 3.0.0.beta4
ruby -v
ruby 1.8.7 (2009-12-24 patchlevel 248) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2010.01 -
Stevo
Just tested it against some other model to make sure that it is not model specific somehow...
>>User.count => 2 >>User.limit(1).count => 2 >>User.limit(1).size => 2 >>User.limit(1).length => 1Edited by Rohit Arondekar for formating
-
Santiago Pastorino
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale