-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing string hash values to AR order method #10732
Allow passing string hash values to AR order method #10732
Conversation
end | ||
|
||
def test_nothing_raises_on_upcase_desc_arg | ||
assert_nothing_raised { Topic.order(:id => "DESC") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we also verify that it's sorting the right way and not just that it does not raise an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be tested in "test_finding_with_assoc_order_with_string". However, I modified the test a bit so it's more exact...
I think this behavior is reasonable. I added a few minor comments and you also need to add a CHANGELOG entry. |
Added CHANGELOG, changed syntax notation and added some more tests. |
@marceloeloelo : Could you please rebase this pull request? This doesn't merge cleanly. |
@robin850 rebased! |
@@ -1,3 +1,11 @@ | |||
* Allow passing string values to AR order method: | |||
Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a blank line before Example:
@pftg if I remember correctly you sent a PR about that part of the code. Is this patch still needed on |
@senny I think that this patch is fully works, but there are some places after validating order args (at least in method |
can someone push a rebased and updated version of this PR? |
I hope this gets fixed before Rails 4.1.0 is officially released. This is very helpful actually. 👍 Also, if I may add, is there any publicly accessible rails constant out there which contains an array of :asc and :desc? I think this can be helpful for the views to determine which order to use. |
…_hash Follow up of #10732 - Allow string hash values on AR order method
The order method from AR supports different kinds of arguments. When using a hash as the parameter this is now supported:
but this is NOT:
I think this is not the behavior that a developer would expect from a method like order, so I added a few changes to support that kind of capabilities.
IMHO, this can be useful when passing 'ASC' or 'DESC' directly from the request params, like for a basic list sorting, without the need of making conversions to symbols, which can be annoying or unclean in some situations...