
Inconsistent result of "order" method
Reported by Georg Ledermann | July 17th, 2009 @ 10:23 AM
Please have a look at this:
>> Document.search("descend_by_datetime" => true).order
=> nil
>> Document.search(:order => "descend_by_datetime").order
=> "descend_by_datetime"
>> Document.search(:order => "datetime DESC").order
=> "datetime DESC"
IMHO the "order" method should always return the same result.
Comments and changes to this ticket
-
Ben Johnson July 30th, 2009 @ 02:50 AM
- State changed from new to open
You make a good point here, but for your examples to pass it would change the underlying logic behind the Search class. The point is just to store values that map to a named scope. So "decend_by_datetime" and :order => "descend_by_datetime" are 2 different named scoped. The order named scope is really just an alias that calls other named scopes. The whole point of it is to make searching with the search object easier. My suggestion is to use "order" when dealing with the search object, and if you aren't you can do whatever you want.
What do you think?
-
Georg Ledermann July 31st, 2009 @ 11:00 AM
I'm trying to understand, hm, but there is still something confusing if I want to get the order of an existing search object. I find out that using proxy_options gives better result:
>> Document.search("descend_by_datetime" => true).proxy_options[:order] => "documents.datetime DESC" # OK! >> Document.search("descend_by_datetime" => true).construct_finder_sql({}) => "SELECT * FROM `documents` ORDER BY documents.datetime DESC" # OK!
>> Document.search(:order => "descend_by_datetime").proxy_options[:order] => "documents.datetime DESC" # OK! >> Document.search(:order => "descend_by_datetime").construct_finder_sql({}) => "SELECT * FROM `documents` ORDER BY documents.datetime DESC" # OK!
But what is this?
>> Document.search(:order => "datetime DESC").order => "datetime DESC" # OK!
documents " # ???
>> Document.search(:order => "datetime DESC").proxy_options => {} # ???
>> Document.search(:order => "datetime DESC").construct_finder_sql({}) => "SELECT * FROMYou see that the proxy_options are blank and the last SQL statement has no ORDER BY.
Maybe I'm the only one who is confused, maybe it's because I'm going on holiday tomorrow ;-)Best wishes,
Georg -
Ben Johnson July 31st, 2009 @ 11:56 AM
That's because the :order condition MUST be a named scope, you can't pass raw SQL.
-
-
Georg Ledermann July 31st, 2009 @ 03:31 PM
Ok, totally agree. To avoid irritations, what about raising an exception (like "UnknownOrderError") if someone gives raw SQL (or unknown order scope) to the :order key? I think this would be a good thing, because there is already a Searchlogic::Search::UnknownConditionError raised for wrong :condition value.
-
Ben Johnson August 7th, 2009 @ 06:30 PM
- State changed from open to moved_to_github
[state:"moved_to_github" bulk edit command]
-
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Provides common named scopes and object based searching.