Friday, February 18, 2011

Re: [Rails] Replacing the ID with the value

On 17 February 2011 21:50, jsmax <popov.max@gmail.com> wrote:
> irb(main):001:0> User.first
> => #<User id: 1, name: "John Smith", group_id: 3>
>
> How can i do that besides the "group_id: 3" result the query will
> return the Group name too. For example:

Have a look at the documentation:
http://ar.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

"Eager loading" is probably your friend, but you can also do what you
want by changing the :select option of any AR query.

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate