Forum: Ruby on Rails belongs_to loop?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gerard (Guest)
on 2005-12-25 16:43
(Received via mailing list)
Hi all,

I'm having two tables: contacts (belongs_to) company details. The
problem is
this. In the company table I have a field "pid" (parent id). Which
relates a
company (being a possible subsidiary) to it's parent e.g. a bigger
enterprise. Does the belongs_to work when related to the same model

The relation is upwards only for now. I don't want to see all
subsidiaries of
an enterprise (yet). Do I need a seperate table to establisch this link
properly in my data scheme?

Thanx (again)


"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
Anocha Yimsiriwattana (Guest)
on 2005-12-26 07:32
(Received via mailing list)
Gerard wrote:

> properly in my data scheme?
> Thanx (again)
> Gerard
Hmm ... it's seem to be a composite pattern for me. Check the key word,
"act_as_tree" in Rails, it's should be the solution for you.

This topic is locked and can not be replied to.