Forum: Ruby on Rails depth needed in model()

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.
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-05 22:20
(Received via mailing list)
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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-05 23:23
(Received via mailing list)
Xavier Noria 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.
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-06 11:34
(Received via mailing list)
On Mar 5, 2006, at 23:22, Alex Young wrote:

> Xavier Noria 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
This topic is locked and can not be replied to.