提交 f1a15c21 编写于 作者: J Jon Leighton 提交者: Aaron Patterson

Abstract a bit more into SingularAssociation

上级 115eedbb
......@@ -3,8 +3,7 @@ module ActiveRecord
module Associations
class BelongsToAssociation < SingularAssociation #:nodoc:
def replace(record)
record = record.target if AssociationProxy === record
raise_on_type_mismatch(record) if record
record = check_record(record)
update_counters(record)
replace_keys(record)
......
......@@ -3,8 +3,7 @@ module ActiveRecord
module Associations
class HasOneAssociation < SingularAssociation #:nodoc:
def replace(record, save = true)
record = record.target if AssociationProxy === record
raise_on_type_mismatch(record) unless record.nil?
record = check_record(record)
load_target
@reflection.klass.transaction do
......
......@@ -26,6 +26,12 @@ def replace(record)
def set_new_record(record)
replace(record)
end
def check_record(record)
record = record.target if AssociationProxy === record
raise_on_type_mismatch(record) if record
record
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册