Is there a way to specify the default order for models? So you could just do this: items.find(:all).each do ... rather than: items.find(:all, :order=>''name'').each do ... Joe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Joe -- On 31-Aug-06, at 9:45 PM, Joe Ruby wrote:> Is there a way to specify the default order for models?No, there isn''t. For the sake of consistency, I think there should be -- when you''re doing associations you can specify the order there, (as in has_many :foos, :order => ''created_at desc''), so why not a default order for the model? You could always override the find method in your model class, though. Something like: def self.find(*args) if args.first.is_a?(Symbol) args << {} if args.size < 2 args.last.reverse_merge! :order => "#{self.table_name}.name" super args.first, args.last else super end end That would give you a default order by on ''name'', which could be overridden by specifying the :order option explicitly, as per usual. HTH /Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
take a look at this article, it may be of some help for you. http://habtm.com/articles/2006/02/22/nested-with_scope this article basically explains various ways to utilize with_scope. one of the methods addresses a very similar situation to yours, however, it is done at the controller level rather than the model. it still may be useful to you. Chris On 8/31/06, Joe Ruby <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Is there a way to specify the default order for models? So you could > just do this: > > items.find(:all).each do ... > > rather than: > > items.find(:all, :order=>''name'').each do ... > > Joe > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---