提交 c76549d6 编写于 作者: A Aaron Patterson

remove the nil check from set_inverse_instance

methods that call set_inverse_instance with a record will not have to
pay the cost of a nil check on every call
上级 da3891c8
......@@ -104,11 +104,12 @@ def reset_scope
# Set the inverse association, if possible
def set_inverse_instance(record)
if record && invertible_for?(record)
if invertible_for?(record)
inverse = record.association(inverse_reflection_for(record).name)
inverse.target = owner
inverse.inversed = true
end
record
end
# Returns the class of the target. belongs_to polymorphic overrides this to look at the
......
......@@ -12,7 +12,7 @@ def replace(record)
update_counters(record)
replace_keys(record)
set_inverse_instance(record)
set_inverse_instance(record) if record
@updated = true if record
......
......@@ -11,7 +11,7 @@ def preload(preloader)
association = owner.association(reflection.name)
association.target = record
association.set_inverse_instance(record)
association.set_inverse_instance(record) if record
end
end
......
......@@ -39,7 +39,9 @@ def create_scope
end
def find_target
scope.first.tap { |record| set_inverse_instance(record) }
if record = scope.first
set_inverse_instance record
end
end
def replace(record)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册