Forum: Ruby on Rails Eager loading of polymorphic 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.
B13a9240291ffa22215214316bd365de?d=identicon&s=25 Hendrik Mans (Guest)
on 2006-03-31 19:20
(Received via mailing list)
Polymorphic associations work great until I try to do some eager
loading through :include. In my example, the interface name is
":imagehaver". Here's my little eagerly loading find line:

Image.find(params[:id], :include => :imagehaver)

All it gives me is an ActiveRecord::EagerLoadPolymorphicError with no
further explanation. I haven't been able to dig up anything useful
through Google, so I'm worried (or hoping?) that it could just be my
code. Any ideas?

Cheers.

--
http://www.mans.de
27c170f482104299af279902be0a9c26?d=identicon&s=25 Trevor Squires (Guest)
on 2006-03-31 19:51
(Received via mailing list)
Hi Hendrik,

Unless something has changed since I last looked at it, eager loaded
associations are pulled in with a single select.

So if you think about it, AR can't build the "from" portion of the
select until *after* it's read the resultset to see what tables the
polymorphic associations belong to.

Regards,
Trevor
--
Trevor Squires
http://somethinglearned.com
B13a9240291ffa22215214316bd365de?d=identicon&s=25 Hendrik Mans (Guest)
on 2006-03-31 19:57
(Received via mailing list)
> So if you think about it, AR can't build the "from" portion of the
> select until *after* it's read the resultset to see what tables the
> polymorphic associations belong to.

Gah! You are correct. I guess this is what happens when you spend too
much time in shiny happy ActiveRecord land. :-) Thanks!

--
http://www.mans.de
This topic is locked and can not be replied to.