Re: has_many

Grégory Pardoen
2007-07-21T19:40:27Z

Josh Susser wrote:
> 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

Thanks for those informations.

I didn''t think about :through .
And I agree for the use of ror''s convention.

I will try that.

Best regards,

Greg

--
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