Created
February 2, 2010 15:44
-
-
Save andrewroth/292755 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
def before_destroy | |
associations_with_data.each { |assoc| | |
errors.add(:assoc, "association has data") | |
} | |
end | |
def associations_with_data | |
associations_with_data = [] | |
self.class.reflect_on_all_associations.each { |assoc| | |
associations_with_data << assoc.name if self.send(assoc.name).present? | |
} | |
return associations_with_data | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment