Permalink
Browse files

push up the loaded target checking

  • Loading branch information...
1 parent 8c155a6 commit d9a7f86666a8f4345fc2b4680ec9b407294a6cc0 @tenderlove tenderlove committed Oct 12, 2013
Showing with 13 additions and 9 deletions.
  1. +13 −9 activerecord/lib/active_record/associations/join_dependency.rb
@@ -216,6 +216,12 @@ def construct(ar_parent, parent, row, rs)
if node.reflection.collection?
other = ar_parent.association(node.reflection.name)
other.loaded!
+ else
+ if ar_parent.association_cache.key?(node.reflection.name)
+ model = ar_parent.association(node.reflection.name).target
+ construct(model, node, row, rs)
+ next
+ end
end
next if row[node.aliased_primary_key].nil?
@@ -226,19 +232,17 @@ def construct(ar_parent, parent, row, rs)
end
end
- def construct_model(record, join_part, row)
- if join_part.reflection.collection?
- model = join_part.instantiate(row)
- other = record.association(join_part.reflection.name)
+ def construct_model(record, node, row)
+ model = node.instantiate(row)
+ other = record.association(node.reflection.name)
+
+ if node.reflection.collection?
other.target.push(model)
- other.set_inverse_instance(model)
else
- return record.association(join_part.reflection.name).target if record.association_cache.key?(join_part.reflection.name)
- model = join_part.instantiate(row)
- other = record.association(join_part.reflection.name)
other.target = model
- other.set_inverse_instance(model)
end
+
+ other.set_inverse_instance(model)
model
end
end

0 comments on commit d9a7f86

Please sign in to comment.