Forum: Ruby on Rails preventing delete of parent with children.

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.
Ddc850a63a423c3ff963bdf3a097652f?d=identicon&s=25 Larry Kelly (ldk2005)
on 2007-01-26 15:25
(Received via mailing list)
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
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-01-26 15:37
(Received via mailing list)
On Jan 26, 2007, at 9:24 AM, Larry Kelly 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/Call...
http://api.rubyonrails.org/classes/ActiveRecord/Ca...

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.