mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
avoiding a few closure references by evaling. [#4223 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
This commit is contained in:
@@ -1545,15 +1545,19 @@ module ActiveRecord
|
||||
|
||||
case name
|
||||
when :destroy, :delete
|
||||
define_method(method_name) do
|
||||
association = send(reflection.name)
|
||||
association.send(name) if association
|
||||
end
|
||||
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
||||
def #{method_name}
|
||||
association = #{reflection.name}
|
||||
association.#{name} if association
|
||||
end
|
||||
eoruby
|
||||
when :nullify
|
||||
define_method(method_name) do
|
||||
association = send(reflection.name)
|
||||
association.update_attribute(reflection.primary_key_name, nil) if association
|
||||
end
|
||||
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
||||
def #{method_name}
|
||||
association = #{reflection.name}
|
||||
association.update_attribute(#{reflection.primary_key_name.inspect}, nil) if association
|
||||
end
|
||||
eoruby
|
||||
else
|
||||
raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify (#{reflection.options[:dependent].inspect})"
|
||||
end
|
||||
@@ -1571,10 +1575,12 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
method_name = :"belongs_to_dependent_#{name}_for_#{reflection.name}"
|
||||
define_method(method_name) do
|
||||
association = send(reflection.name)
|
||||
association.send(name) if association
|
||||
end
|
||||
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
||||
def #{method_name}
|
||||
association = #{reflection.name}
|
||||
association.#{name} if association
|
||||
end
|
||||
eoruby
|
||||
after_destroy method_name
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user