Dont reload on empty associations

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1231 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 77af61be
......@@ -702,16 +702,18 @@ def find_with_associations(options = {})
record = records[id]
reflections.each do |reflection|
next unless row[primary_key_table[reflection.table_name]]
case reflection.macro
when :has_many, :has_and_belongs_to_many
collection = record.send(reflection.name)
collection.loaded
next unless row[primary_key_table[reflection.table_name]]
association = reflection.klass.send(:instantiate, extract_record(schema_abbreviations, reflection.table_name, row))
collection.target.push(association) unless collection.target.include?(association)
when :has_one, :belongs_to
next unless row[primary_key_table[reflection.table_name]]
record.send(
"#{reflection.name}=",
reflection.klass.send(:instantiate, extract_record(schema_abbreviations, reflection.table_name, row))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册