Hi, I have a model Person that has a Bag that has Content. Person has Content as well. A Bag cannot be destroyed if it is not empty. In Person: has_many :bags, :dependent => :destroy # A has_many :contents, :dependent => :destroy # B In Bag: has_many :contents, :dependent => :destroy # C If I destroy a Person with a non empty Bag, I get an error (correct). By swapping A and B the error disappears. (First destroy all Content => all Bags are empy) This is what I wanted, but I could not find this documented, so I don''t know if I can rely on this Do you know anything about this? Thanks, Mauro -- 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 -~----------~----~----~----~------~----~------~--~---
Does every "content" belong to a bag? If so, you''re probably trying to delete the same thing twice. You might try getting rid of the dependent statement on #b, and let the bag destroy its contents.. Cheers Starr --- www.thebootstrapnation.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 -~----------~----~----~----~------~----~------~--~---
The question is:
"can I rely on the destroy order to be the same of order the declaration
order?"
In other words: can I assume, given
class Person < ActiveRecord::Base
has_many :bags, :dependent => :destroy # A
has_many :contents, :dependent => :destroy # B
end
that destroying an object of type Person
_first_ destroys bags and only _then_ contents?
This is already happening, but I am not sure that it is not by accident
Mauro
--
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
-~----------~----~----~----~------~----~------~--~---