mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
avoiding a few closure references by evaling. [#4223 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
This commit is contained in:
parent
753304bd11
commit
3172db12e4
1 changed files with 18 additions and 12 deletions
|
@ -1545,15 +1545,19 @@ module ActiveRecord
|
||||||
|
|
||||||
case name
|
case name
|
||||||
when :destroy, :delete
|
when :destroy, :delete
|
||||||
define_method(method_name) do
|
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
||||||
association = send(reflection.name)
|
def #{method_name}
|
||||||
association.send(name) if association
|
association = #{reflection.name}
|
||||||
|
association.#{name} if association
|
||||||
end
|
end
|
||||||
|
eoruby
|
||||||
when :nullify
|
when :nullify
|
||||||
define_method(method_name) do
|
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
||||||
association = send(reflection.name)
|
def #{method_name}
|
||||||
association.update_attribute(reflection.primary_key_name, nil) if association
|
association = #{reflection.name}
|
||||||
|
association.update_attribute(#{reflection.primary_key_name.inspect}, nil) if association
|
||||||
end
|
end
|
||||||
|
eoruby
|
||||||
else
|
else
|
||||||
raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify (#{reflection.options[:dependent].inspect})"
|
raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify (#{reflection.options[:dependent].inspect})"
|
||||||
end
|
end
|
||||||
|
@ -1571,10 +1575,12 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
method_name = :"belongs_to_dependent_#{name}_for_#{reflection.name}"
|
method_name = :"belongs_to_dependent_#{name}_for_#{reflection.name}"
|
||||||
define_method(method_name) do
|
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
||||||
association = send(reflection.name)
|
def #{method_name}
|
||||||
association.send(name) if association
|
association = #{reflection.name}
|
||||||
|
association.#{name} if association
|
||||||
end
|
end
|
||||||
|
eoruby
|
||||||
after_destroy method_name
|
after_destroy method_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue