From 5d663a712297f0c62ea948cbe2765e6acac839ab Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 11 Oct 2013 15:42:48 -0700 Subject: reflections know if they are collections, so ask We don't need to poke at the macro to figure out if we should look for a cached record or not --- .../lib/active_record/associations/join_dependency.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index d91307d972..58c315f48b 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -220,17 +220,16 @@ module ActiveRecord end def construct_association(record, join_part, row) - macro = join_part.reflection.macro - 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 + if join_part.reflection.collection? association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil? other = record.association(join_part.reflection.name) other.loaded! other.target.push(association) if association other.set_inverse_instance(association) + else + 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) end association end -- cgit v1.2.3