Forum: Ruby on Rails :dependent => :destroy_unconditionally?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-03-06 17:12
(Received via mailing list)
Hey...

I have these business_accounts that have a bunch of members through a
business_account_membership model. A membership can be a privileged,
"managing" one, and a business account should always have one such
privileged member, so I have a before_destroy filter on the
business_account_membership model to prevent the deletion of the last
managing member of a business account.

However, when deleting a business account, this constraint should no
longer be respected - if the business account dies, then the rule dies
with it. Only thing is, Rails tries to destroy all those managing
members before destroying the business account itself, because they're
related like this:
     has_many :members, { :class_name =>
'BusinessAccountMembership', :dependent => :destroy }

I would like to define in this relationship, or somewhere else, that
the dependent members should be destroyed without validating against
my before_destroy
filter :prevent_deletion_of_exclusive_business_account_manager.

Any ideas as to how I would go about doing that?

Thanks in advance,
Daniel :)
This topic is locked and can not be replied to.