[Rails] ActiveRecord selecting multiple fields
Tobias Luetke
tobias.luetke at gmail.com
Sun Nov 7 15:10:51 GMT 2004
def fullname
"#{first_name} #{self.last_name}"
end
person = Person.find(1)
person.fullname
On Mon, 8 Nov 2004 00:32:20 +1100, Bruno Mattarollo <bmatt at mac.com> wrote:
> Hello,
>
> I have a model for a Person and I am trying to get the "first_name" and
> the "last_name" which I have in different columns in a table. Is this
> the most efficient way?
>
> def self.getFullName(user_id)
> find(user_id).first_names + " " + find(user_id).last_name
> end
>
> I assume that this makes two queries ... I would like to only make one
> (also for future stuff ... how do I make this more efficient?)
>
> Thank you in advance,
>
> /B
>
> --
> Bruno Mattarollo <bmatt at mac.com>
> Currently in: Sydney, Australia
> [ http://pokies.typepad.com/virtual_possum/ ]
>
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>
--
Tobi
More information about the Rails
mailing list