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

drying up construct_association

上级 8186c573
......@@ -1978,27 +1978,27 @@ def construct(parent, associations, joins, row)
def construct_association(record, join, row)
return if record.id.to_s != join.parent.record_id(row).to_s
case join.reflection.macro
when :has_many, :has_and_belongs_to_many
collection = record.send(join.reflection.name)
collection.loaded
return if row[join.aliased_primary_key].nil?
association = join.instantiate(row)
collection.target.push(association)
collection.__send__(:set_inverse_instance, association, record)
when :has_one
macro = join.reflection.macro
if macro == :has_one
return if record.instance_variable_defined?("@#{join.reflection.name}")
association = join.instantiate(row) unless row[join.aliased_primary_key].nil?
set_target_and_inverse(join, association, record)
when :belongs_to
else
return if row[join.aliased_primary_key].nil?
association = join.instantiate(row)
set_target_and_inverse(join, association, record)
else
raise ConfigurationError, "unknown macro: #{join.reflection.macro}"
case macro
when :has_many, :has_and_belongs_to_many
collection = record.send(join.reflection.name)
collection.loaded
collection.target.push(association)
collection.__send__(:set_inverse_instance, association, record)
when :belongs_to
set_target_and_inverse(join, association, record)
else
raise ConfigurationError, "unknown macro: #{join.reflection.macro}"
end
end
return association
association
end
def set_target_and_inverse(join, association, record)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册