提交 3172db12 编写于 作者: A Aaron Patterson 提交者: wycats

avoiding a few closure references by evaling. [#4223 state:resolved]

Signed-off-by: Nwycats <wycats@gmail.com>
上级 753304bd
......@@ -1545,15 +1545,19 @@ def configure_dependency_for_has_one(reflection)
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 @@ def configure_dependency_for_belongs_to(reflection)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册