aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/association.rb
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2012-01-29 15:24:03 +0100
committerManoj <manoj.kumar@risingsuntech.net>2012-01-31 14:10:19 +0530
commit3053f52671164530b811238f86954cb96f6ebc16 (patch)
tree29136ed1122a6f9fc9db6e3899770361cac0cbbe /activerecord/lib/active_record/associations/builder/association.rb
parent38ffca55ab806990b35f23b44540f9eef90461c1 (diff)
downloadrails-3053f52671164530b811238f86954cb96f6ebc16.tar.gz
rails-3053f52671164530b811238f86954cb96f6ebc16.tar.bz2
rails-3053f52671164530b811238f86954cb96f6ebc16.zip
Same method for has_many and has_one associations
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/association.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index 54e51b7f44..45d3f37089 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -65,5 +65,20 @@ module ActiveRecord::Associations::Builder
ActiveSupport::Deprecation.warn msg
end
end
+
+ def define_restrict_dependency_method
+ name = self.name
+ mixin.redefine_method(dependency_method_name) do
+ # has_many or has_one associations
+ if send(name).respond_to?(:exists?) ? send(name).exists? : !send(name).nil?
+ if dependent_restrict_raises?
+ raise ActiveRecord::DeleteRestrictionError.new(name)
+ else
+ errors.add(:base, :restrict_dependent_destroy, :model => name)
+ return false
+ end
+ end
+ end
+ end
end
end