Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 5d663a712297f0c62ea948cbe2765e6acac839ab 1 parent 8219691
Aaron Patterson tenderlove authored
Showing with 5 additions and 6 deletions.
  1. +5 −6 activerecord/lib/active_record/associations/join_dependency.rb
11 activerecord/lib/active_record/associations/join_dependency.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.