提交 8219691e 编写于 作者: A Aaron Patterson

belongs_to can be treated the same way as has_one

上级 3a8892aa
......@@ -221,23 +221,16 @@ def construct(ar_parent, parent, row, rs)
def construct_association(record, join_part, row)
macro = join_part.reflection.macro
if macro == :has_one
if macro == :has_one || macro == :belongs_to
return record.association(join_part.reflection.name).target if record.association_cache.key?(join_part.reflection.name)
association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
set_target_and_inverse(join_part, association, record)
else
association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
case macro
when :has_many
other = record.association(join_part.reflection.name)
other.loaded!
other.target.push(association) if association
other.set_inverse_instance(association)
when :belongs_to
set_target_and_inverse(join_part, association, record)
else
raise ConfigurationError, "unknown macro: #{join_part.reflection.macro}"
end
other = record.association(join_part.reflection.name)
other.loaded!
other.target.push(association) if association
other.set_inverse_instance(association)
end
association
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册