Preventing delete of parent with children


#1

I’m lookin for an equilvalent to SQL ‘… on delete restrict’. To
prevent
deleting a parent record if there are related children records.
Looking at
the :dependent => options I see

:dependent => :destroy and :dependent => :nullify,
but not a :dependent => :restrict?

What is the best solution in this case?


Best Regards,
-Larry
“Work, work, work…there is no satisfactory alternative.”
— E.Taft Benson


#2

On Jan 26, 2007, at 9:24 AM, Larry K. wrote:

Best Regards,
-Larry
“Work, work, work…there is no satisfactory alternative.”
— E.Taft Benson

Use a before_destroy callback on the parent?

http://rdoc.caboo.se/doc/classes/ActiveRecord/Callbacks.html#M005369
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M000920

-Rob

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid