From 3140e37d18c66527a80a153727a7ea972b80506a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 19 Apr 2005 16:59:30 +0000 Subject: Dont reload on empty associations git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1231 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 017689b9cd..e447da3051 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -702,16 +702,18 @@ module ActiveRecord 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)) -- cgit v1.2.3