Forum: Ruby on Rails ActiveRecord eager loading of associations

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.
anatol.pomozov (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hi, All.

I have following model.

Category has_many_and_belongs to Property. Property belongs_to Term.

In controller i receive category_id from user. I need to load for this
category all properties that belongs to Category *with* it's term.

For now I have following code

@props = Category.find(@params[:selected_category]).properties

and in view
for each p in @props
<%p.term.name%>

but as I understand term not loaded in Category.find so <%p.term.name%>
throws "nil have no name method". (p.term is nil)

So my question is simple how to load term during find.

Thanks for any response.

--
anatol
anatol.pomozov (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Is it really no way to switch on eager loading for sccotioations??

I could not beleive that ActiveRecord have no solutions for it...

On 11/8/05, Anatol Pomozov <anatol.pomozov@gmail.com> wrote:
> For now I have following code
> So my question is simple how to load term during find.
>
> Thanks for any response.
>
> --
> anatol




--
anatol
This topic is locked and can not be replied to.