Hi everyone
Is there a way that I can get the find(:all) method to return in a
specified
order, without including the :order argument every time?
Guess I just don’t like typing…
Cheers
Hi everyone
Is there a way that I can get the find(:all) method to return in a
specified
order, without including the :order argument every time?
Guess I just don’t like typing…
Cheers
You could always define your own subroutine
liquid wrote:
Is there a way that I can get the find(:all) method to return in a
specified order, without including the :order argument every time?
A default table order sounds like a MySQL thing. You can specify an
order for your associations though:
has_many :velvet_elvis_posters, :order => 'velvetiness desc'
Guess I just don’t like typing…
This is a good thing. If it weren’t for people like you, we’d still be
using Java.
On Friday 25 November 2005 07:01, Liquid wrote:
Hi everyone
Is there a way that I can get the find(:all) method to return in a
specified order, without including the :order argument every time?
Override the find method in that model?
or
class Foo < ActiveRecord::Base
…
def my_find
find(:all, …)
end
…
end
Then use my_find where you would have used find.
My non-expert opinion is that 2. is slightly better than 1. because you
may at some point need another version of find sorted differently and
you may make life more difficult by modifying the default behaviour of
find rather than adding a new version with its own behaviour.
Guess I just don’t like typing…
Cheers
HTH,
Thanx for the suggestions guys…
I have thought of trying to extend ActiveRecord… I’m not completely
sure
how to do that yet. What I’ve been thinking of is to overwrite the find
method, and if there is no :order argument defined, I would like to put
an
instance or class variable in my model, that I include as the :order
argument
eg
class SomeModel < ActionRecord
@@order = ‘the_order_field, another_field’
…
end
Then whenever the find method is called. If there is no :order
specified,
order by @@order. If there is no @@order specified just execute the
original find…
The reason for this is because I’m trying to use an engine, but I want
to
specify what order the lists are presented without going into that code
at
all.
Any help would be great.
Cheers
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs