# Dynamic relation with eager loading

**URL:** <https://www.ruby-forum.com/t/dynamic-relation-with-eager-loading/119633>\
**Category:** Rails\
**Created:** [November 8, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/dynamic-relation-with-eager-loading/119633 "2007-11-08T19:24:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![keynan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@keynan](https://www.ruby-forum.com/u/keynan)\
**Post date:** [November 8, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/dynamic-relation-with-eager-loading/119633/1 "2007-11-08T19:24:37Z")

</div>

A model has 2 columns in its table

asset\_type\_id  
asset\_id

the asset\_type\_id links directly to the table asset\_types via a  
belongs\_to

asset\_types contains a single column ‘name’

method\_missing in the model says when you call a method matching  
/^asset.\*/  
call the corresponding method substituting ‘asset’ for the contents of  
asset\_type.name

(ie. the name in asset\_types is the name of a table&model)

So far it works wonderfully. However, I would like to be able to eagerly  
load via the assets.

Does any one know what I would have to do to to make this work without  
eager loading all of the possible types of assets  
(ie. eager load all models that exist in table asset\_types)
