You could always use inheritance.
class Book < ActiveRecord::Base
def destroy
return super if page.empty?
return false
end
end
On Mar 29, 11:10 am, Neal L <[email protected]> wrote:
> This is a total noob question, but how do you prevent a record from
> being destroyed if it has any related records. In my case, I have a
> book model and a page model. A book has_many pages.
>
> How do I prevent book.destroy from destroying a book if it has
> associated page records? Is there a :dependent option that would do
> this? Do I need to do some sort of before destroy callback?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---