Permalink
Browse files

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
  • Loading branch information...
1 parent 8219691 commit 5d663a712297f0c62ea948cbe2765e6acac839ab @tenderlove tenderlove committed Oct 11, 2013
Showing with 5 additions and 6 deletions.
  1. +5 −6 activerecord/lib/active_record/associations/join_dependency.rb
View
11 activerecord/lib/active_record/associations/join_dependency.rb
@@ -220,17 +220,16 @@ def construct(ar_parent, parent, row, rs)
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

0 comments on commit 5d663a7

Please sign in to comment.