Here's my proposed patch. It ensures that :order => :default always
sets an order.
Comments? (some CSE could be applied but the patch is more readable this way)
--- a/vendor/plugins/hobo/hobo/lib/hobo/model.rb
+++ b/vendor/plugins/hobo/hobo/lib/hobo/model.rb
@@ -277,7 +277,14 @@ module Hobo
options = args.extract_options!
if options[:order] == :default
options = if default_order.blank?
- options.except :order
+ options.merge(:order => if columns_hash['created_at']
+ "#{table_name}.created_at"
+ elsif columns_hash['created_on']
+ "#{table_name}.created_on"
+ else
+ "#{table_name}.#{primary_key}"
+ end
+ )
else
options.merge(:order => if default_order[/(\.|\(|,| )/]
default_order
On Thu, Mar 12, 2009 at 2:25 PM, Scott Bronson <[email protected]> wrote:
> Actually, it's even easier to specify the default order for a model:
>
> class User < ActiveRecord::Base
> set_default_order "name, created_at DESC"
> end
>
> always learning new things...
>
>
> On Thu, Mar 12, 2009 at 1:59 PM, Scott Bronson <[email protected]> wrote:
>> If you specify :order => :default to a finder, Hobo will guess a
>> default ordering to use. Hobo also ensures that paginating find
>> always specifies :order => :default. This is very cool.
>>
>> So, how does Hobo figure out what the default order should be? If
>> your model specifies a default_order method (returning either the name
>> of a column or a string suitable for find's :order parameter), then
>> Hobo uses that.
>>
>> But here's the catch... If your model doesn't specify default_order,
>> then Hobo doesn't specify any ordering at all! This tends to work OK
>> on MySQL and sqlite, not so well on Postgres, and falls apart on SQL
>> Server.
>>
>> Shouldn't Hobo ensure that some sort of ordering is specified?
>> will_paginate's docs suggest that this is pretty important.
>> http://github.com/mislav/will_paginate/blob/8888651be8d6656bdf2378731d91a8badbaa2556/lib/will_paginate/finder.rb
>> (search for "The importance of the :order parameter)
>>
>> And, if so, then how should Hobo figure out what the default order
>> would be? created_at/created_on if it exists, otherwise primary key?
>>
>> Is this worth fixing? I'm happy to write the patch if you guys think
>> this is a good idea.
>>
>> - Scott
>>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---