Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #4835 from pacoguzman/refactor_define_restrict_dep…

…endency_method

Refactor define_restrict_dependency_method using reflection
  • Loading branch information...
commit 8405aad6fb0a67367c9e2ce53346ae74927edf9c 2 parents f20032f + 1596878
@carlosantoniodasilva carlosantoniodasilva authored
View
6 activerecord/lib/active_record/associations/builder/association.rb
@@ -69,12 +69,12 @@ def dependent_restrict_deprecation_warning
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?
+ has_one_macro = association(name).reflection.macro == :has_one
+ if has_one_macro ? !send(name).nil? : send(name).exists?
if dependent_restrict_raises?
raise ActiveRecord::DeleteRestrictionError.new(name)
else
- key = association(name).reflection.macro == :has_one ? "one" : "many"
+ key = has_one_macro ? "one" : "many"
errors.add(:base, :"restrict_dependent_destroy.#{key}",
:record => self.class.human_attribute_name(name).downcase)
return false
Please sign in to comment.
Something went wrong with that request. Please try again.