提交 6772d5e7 编写于 作者: A Aaron Patterson

pull a nil check up one frame

上级 a176bd09
......@@ -40,7 +40,15 @@ def find_target?
def update_counters(record)
counter_cache_name = reflection.counter_cache_column
if counter_cache_name && owner.persisted? && different_target?(record)
return unless counter_cache_name && owner.persisted?
diff_target = if record
different_target?(record)
else
owner[reflection.foreign_key]
end
if diff_target
if record
record.class.increment_counter(counter_cache_name, record.id)
end
......@@ -53,11 +61,7 @@ def update_counters(record)
# Checks whether record is different to the current target, without loading it
def different_target?(record)
if record.nil?
owner[reflection.foreign_key]
else
record.id != owner[reflection.foreign_key]
end
record.id != owner[reflection.foreign_key]
end
def replace_keys(record)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册