This project is archived and is in readonly mode.
scopes using `reorder` don't override `default_scope` order
-
Neeraj Singh
- Milestone set to 3.x
- State changed from new to hold
- Assigned user set to Neeraj Singh
- Importance changed from to Low
Thanks for reporting the bug. There is a discussion going on about how to handle default_scope in ticket #5519. Until that ticket is resolved I am putting this on on hold.
-
Nick Ragaz
Thanks for the quick review. I guess my view would be that the "shipped" API in v3.0 should be honoured, and I'm pretty sure that this behaviour was introduced accidentally...
-
Santiago Pastorino
- Milestone cleared.
- State changed from hold to open
-
José Valim
Actually, reorder should always override the default scope. The current state is definitely a bug.
-
Santiago Pastorino
- State changed from open to committed
-
Nick Ragaz
Sadly, there is still an issue - at least, I think there is - if you have multiple scopes chained, like so:
class Foo < ActiveRecord::Base default_scope order('id') scope :name_is_nil, where(:name => nil) scope :name_order, reorder('name') scope :age_order, reorder('age') end Foo.name_order.age_orderYou will get SQL like:
SELECT * FROM foos ORDER BY name, ageWhere I would expect:
SELECT * FROM foos ORDER BY agei.e. that the last
reorderscope in the chain would take precedence.Also, the current behaviour will produce:
Foo.name_order.name_is_nil.age_order.to_sql # => "SELECT * FROM foos ORDER BY name, id, age" -
Santiago Pastorino
- State changed from committed to open
- Milestone changed from 3.0.2 to 3.1
- Assigned user changed from Neeraj Singh to Santiago Pastorino
This is actually a bug in 3.1 and the solution of 3.0.x is the ugliest I've ever seen. I can say that without worrying about hurting anybody's feelings since I've made it .
