Re: [Rails] Re: Rails 3 ActiveRecord queries - I'm missing something very BIG
On 18 November 2010 22:24, comopasta Gr <lists@ruby-forum.com> wrote:
> Thanks Philip!
>
> Yeah I wanted to include the tasks while getting the project.
>
> I think this does it Rails 3 way:
> @proj = Project.includes(:tasks).find_by_id(params[:id])
>
> @proj.tasks returns the array of tasks and looks much better.
Just a note to point out that the .includes(:tasks) is not required.
@proj.tasks will still work without it (unless this has changed in
rails 3). Using includes will reduce the number of hits on the db
however.
Colin
--
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