提交 4c1d2218 编写于 作者: R Ryuta Kamizono

Evaluate the default block only when necessary

Follow up of #28453.
上级 cf4f05a7
......@@ -21,8 +21,8 @@ def replace(record)
self.target = record
end
def default(record)
writer(record) if reader.nil?
def default(&block)
writer(instance_exec(&block)) if reader.nil?
end
def reset
......
......@@ -121,7 +121,7 @@ def self.add_touch_callbacks(model, reflection)
def self.add_default_callbacks(model, reflection)
model.before_validation lambda { |o|
o.association(reflection.name).default o.instance_exec(&reflection.options[:default])
o.association(reflection.name).default(&reflection.options[:default])
}
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册