model_iterator
model_iterator copied to clipboard
Iteration is broken when the AR model specifies its own default order via `default_scope`
Take this example default scope:
default_scope :order => "created_at DESC"
The SQL queries resulting from model iterator for the above model will end up having this clause:
ORDER BY created_at DESC, id asc
Because the order is messed up right now, @current_id won't be properly maintained and the iterator will go through many more iterations of overlapping sets of records than it's needed.
The solution would be to ensure that the default_scope order is never inherited.
/cc @ptoomey3