aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-11 15:42:48 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-11 15:53:25 -0700
commit5d663a712297f0c62ea948cbe2765e6acac839ab (patch)
tree576d97e26ba8f048612db56b8117e1f398e5475d /activerecord/lib
parent8219691ef29cdcd04b784e20e3e790d8e952285c (diff)
downloadrails-5d663a712297f0c62ea948cbe2765e6acac839ab.tar.gz
rails-5d663a712297f0c62ea948cbe2765e6acac839ab.tar.bz2
rails-5d663a712297f0c62ea948cbe2765e6acac839ab.zip
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
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb11
1 files changed, 5 insertions, 6 deletions
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