Re: has_many

Josh Susser
2007-07-21T15:54:16Z

Grégory Pardoen wrote:
> I have a table collection and a table collectionorganisation. The
> collectionorganisation table is used to define a hierarchy between
> collections.
> So, in the table collectionorganisation there is two foreign key :
> parent_id and son_id.
>
> In the collection model, I define the two following has_many with
> dependent => destroy :
>
>   has_many :collectionorganisation, :foreign_key =>
"parent_id",
> :dependent => :destroy
>   has_many :collectionorganisation, :foreign_key => "son_id",
:dependent
> => :destroy
>
> Unfortunatly, only the last depedent(son_id) is took into account. So
> when a delete a collection that is present in the field son_id of a
> record of collectionorganisation, then this record (in
> collectionorganisation) is correctly deleted. But, if the collection is
> present in the field parent_id, then nothing is done.
>
> Someone can help me ?

http://blog.hasmanythrough.com/2006/4/21/self-referential-through

For best results, you''ll want to name your tables according to
Rails''
conventions.

For the Collection model, the table should be `collections`. If the join
model is CollectionOrganization, the table should be
`collection_organizations`.

--
Josh Susser
http://blog.hasmanythrough.com

--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com