Eager loading of polymorphic associations

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

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 S.
http://somethinglearned.com

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. :slight_smile: Thanks!