This project is archived and is in readonly mode.
except(:order).order(...) is not working in scopes
Method reorder that existed before was removed in master and deprecated in 3.0.3 (https://github.com/rails/rails/commit/e0b76d6151821527f16b3f163abde.... Instead must be used except(:order).order(...)
While this works in regular relations it is not working in scopes (does not override the default scope).
E.g. if class DeveloperOrderedBySalary has default_scope :order => 'salary DESC' and named scope
scope :reordered_by_name, except(:order).order('name DESC')
I expect DeveloperOrderedBySalary.reordered_by_name.all to return developers reordered by name while it does not. The test I once created for this was removed. Instead there is a test named test_named_scope_appends_default but I think this name is incorrect as soon as it really tests that ordering defined in named scope is appended to default scope's ordering (i.e. :order => 'salary DESC, name DESC' is expected).
Unfortunately I have no idea how to fix this but I'm attaching a patch with test which I consider appropriate (now failing).
Comments and changes to this ticket
Looks like this happens because reorder_flag was removed. Named scope defined with except(:order).order(xxx) now has no difference with the one defined with order(xxx). So when merging order_value they are merged like they were defined by regular order i.e. are being appended to default_scope's order instead of overwriting them.
When a chain of methods is run on the relation except works correctly because it effectively removes the current order_value of this very relation, but in the scope it does not.
- 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, yes it is. (Just checked). Somehow (not sure) it is because of: https://rails.lighthouseapp.com/projects/8994/tickets/6290-patch-ex...
And because of how the default_scope applies (I think I've figured out why I doesn't work).
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>