Hi, 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 ? Thanks in advance. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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.comThanks 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---