RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: xjunior
Just to add up more info for future visitors:
You can, instead of "include" use "preload". But this will cause a second query to be triggered. This method is recommended since it'll help you to avoid N+1 queries.
Unfortunately eager loading polymorphic associations isn't actually possible. The polymorphic association holds a a class name and an id present on that class. The polymorphic associations, though, don't have a way to join them in a SQL query since SQL doesn't support any sort of meta-programing.
Address is kept in addresses table, and has an addressable reference. In the database there would be "addressable_id" and "addressable_type". There's no way to use "addressable_type" to make an INNER JOIN in the SQL query.