This project is archived and is in readonly mode.
find_each ignores limit
Reported by wtn | March 7th, 2010 @ 10:45 AM | in 3.0.2
The following code iterates over the entire table, ignoring the limit scope:
klass.limit(3).find_each {|obj| puts obj.to_s}
In ActiveRecord 2.3, one could iterate over the first 3000 of 10000 records without loading all 3000 at once. In ActiveRecord 3.0, this is not possible.
find_each works with all other scope methods, so silently discarding limit scopes is inconsistent behavior. I suggest one of two options:
- find_each should ignore limits but issue a warning;
- find_each should behave as under ActiveRecord 2.3 and use the limit.
Comments and changes to this ticket
-
José Valim March 27th, 2010 @ 02:16 PM
If you want to iterate just over three objects, you can simply do klass.limit(3).all.each {}, or am I missing something?
If you want to iterate in batches of 3 though, you need to given :batch_size as option.
-
wtn March 27th, 2010 @ 11:48 PM
- Tag changed from activerecord 3.0 to activerecord 3.0, 3.0.0.beta, activerecord, find_each, limit, scope
In ActiveRecord 2.3, one could iterate over the first 3000 of 10000 records without loading all 3000 at once. In ActiveRecord 3.0, this is not possible.
find_each
works with all other scope methods, so silently discarding limit scopes is inconsistent behavior. I suggest one of two options:find_each
should ignore limits but issue a warning;find_each
should behave as under ActiveRecord 2.3 and use the limit.
-
José Valim March 28th, 2010 @ 04:27 AM
- Assigned user set to Emilio Tagua
- Milestone cleared.
-
Repository March 29th, 2010 @ 04:30 PM
- State changed from new to resolved
(from [53ddbfc460f5a54d5b81e7bfbc1c5828f90488c1]) Warn scoped order and limit are ignored. [#4123 state:resolved] http://github.com/rails/rails/commit/53ddbfc460f5a54d5b81e7bfbc1c58...
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to High
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
Referenced by
- 4123 find_each ignores limit (from [53ddbfc460f5a54d5b81e7bfbc1c5828f90488c1]) Warn sc...