# Depth needed in model()

**URL:** <https://www.ruby-forum.com/t/depth-needed-in-model/54458>\
**Category:** Rails\
**Created:** [March 5, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/depth-needed-in-model/54458 "2006-03-05T22:20:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [March 5, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/depth-needed-in-model/54458/1 "2006-03-05T22:20:05Z")

</div>

If there are models of type M in session, and objects of type M  
contain objects of type M’, does M’ need to be included in model()?

– fxn

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [March 5, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/depth-needed-in-model/54458/2 "2006-03-05T23:23:51Z")

</div>

Xavier N. wrote:

> If there are models of type M in session, and objects of type M contain  
> objects of type M’, does M’ need to be included in model()?  
> If by “contain” you mean has\_many, then I think not… the has\_many  
> method calls require\_association\_class which does the necessary.

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [March 6, 2006, 11:34am UTC](https://www.ruby-forum.com/t/depth-needed-in-model/54458/3 "2006-03-06T11:34:42Z")

</div>

On Mar 5, 2006, at 23:22, Alex Y. wrote:

> Xavier N. wrote:
> 
> > If there are models of type M in session, and objects of type M  
> > contain objects of type M’, does M’ need to be included in model()?  
> > If by “contain” you mean has\_many, then I think not… the  
> > has\_many method calls require\_association\_class which does the  
> > necessary.

I meant “references”, either directly or indirectly by means of some  
standard class like “Array of non-AR models”.

Looks like a good rule of thumb would be: if all child models are  
referenced by means of AR’s DSL like has\_many, has\_one, etc. then  
only the root model needs to be passed to model(). Otherwise pass as  
many models as needed recursively (sounds very fragile). In any case,  
putting a model that would be loaded anyway does not hurt.

Does that look right?

– fxn
