Forum: Ruby on Rails setting "defaults" on AR finds

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
66d1d0df01e4bbb82674a353ea68d6ee?d=identicon&s=25 Josh Kieschnick (jjkiesch)
on 2007-07-24 19:03
(Received via mailing list)
let's say i have a Category model. every time i pull the categories, i
am writing something along the lines of @categories =
Category.find(:all, :order => :position)

is there a way to put something in the model so that any time i find
categories with Category.find(:all), it will automatically sort by the
position column unless i specify otherwise? i would like to be able to
change something like that in one place instead of passing the same
parameters to it every time.

i did add something like this to the model which also works:

  def self.order_by_position
    find(:all, :order => :position)
  end

so that i can just do Category.order_by_position but was just
wondering if there's a better way.
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-07-24 19:58
(Received via mailing list)
> i did add something like this to the model which also works:
>
>  def self.order_by_position
>    find(:all, :order => :position)
>  end
>
> so that i can just do Category.order_by_position but was just
> wondering if there's a better way.

One of these might do it...

http://agilewebdevelopment.com/plugins/search?search=scope
This topic is locked and can not be replied to.