-
Notifications
You must be signed in to change notification settings - Fork 133
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
Multi column ordering #17
Comments
Multi column ordering Yeah, that would be a nice feature and it’s probably something AR scopes should handle anyways. It looks like it will get applied though, I think they are just waiting on better tests. by Ben Johnson |
Multi column ordering Actually my tests are showing that AR does support multi column ordering by chaining named scopes. Are you not seeing that? by Ben Johnson |
Multi column ordering Hm, I tested the following with Rails 2.3.2: @@@ => SELECT * FROM
|
Multi column ordering Yeah, my fault, it does chain them together when you pass order in an action method: User.ascend_by_id.ascend_by_email.first(:order => "test") ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ’test’ in ’order clause’: SELECT * FROM `users` ORDER BY test, users.id ASC LIMIT 1 But for me to make this work I would have to alter the default behavior of AR, which I don’t think is a good idea. I’m not sure what to do. I could do some tricky things in the Search object, but I want that to remain consistent with calling the named scopes directly. by Ben Johnson |
Multi column ordering I agree with you. My current solution to have mutliple ordering is by adding some named scopes like this: Contact.search(:ordered_by_name => true) Somtimes I need to override the predefined searchlogic ordering scopes like this: Preserve insertion order for sorting by datenamed_scope :descend_by_date, :order => ’date DESC, id DESC’ For me, it’s ok to stay with this. We will see if ActiveRecord will merge multiple ordering scopes in the future. by Georg Ledermann |
I would like to have ordering by multiple columns, where each of them can be ascending and descending. Example: "ORDER BY date ASC, id DESC"
What about creating scope like this:
order_by_date_asc_and_id_desc
Sadly, nesting orders with scopes is not possible in Rails 2.3.2, see here:
https://rails.lighthouseapp.com/projects/8994/tickets/2253-named_scope-and-nested-order-clauses
So it should be created as ONE scope.
original LH ticket
This ticket has 0 attachment(s).
The text was updated successfully, but these errors were encountered: