Eager loading outside the find method

0 views
Skip to first unread message

elioncho

unread,
Dec 31, 2009, 3:31:40 AM12/31/09
to Ruby on Rails: Talk
Hello,

I am used tO the :include parameter always inside a find method:

@posts = Post.find(:all, :include => [:user])

How can I wire the :include to the relationship outside the find
method?

@posts = Post.find(:all)
@posts...(HERE THE METHOD TO WIRE UP THE USER TO EACH POST)

Thanks

elioncho

unread,
Dec 31, 2009, 3:45:08 AM12/31/09
to Ruby on Rails: Talk
I just want to know if its possible.

elioncho

unread,
Dec 31, 2009, 4:06:24 AM12/31/09
to Ruby on Rails: Talk
I want to reproduce the internals of eager loading.

Frederick Cheung

unread,
Dec 31, 2009, 5:12:34 AM12/31/09
to Ruby on Rails: Talk

On Dec 31, 9:06 am, elioncho <elion...@gmail.com> wrote:
> I want to reproduce the internals of eager loading.

If you're feeling evil you can do something like

Post.send :preload_associations @posts, :user

(This is a protected method - could easily change between releases of
rails)

Fred

Reply all
Reply to author
Forward
0 new messages