aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-11 17:27:34 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-11 17:27:34 -0700
commit50e6b69018ca4dfcdd30030f1c402da9b0d9563b (patch)
treebd5fdde91ffddecadf66e09e9f81f32027eecbac /activerecord/lib/active_record
parent68c08111fbb78befd1811136a6cbcb157bd3e914 (diff)
downloadrails-50e6b69018ca4dfcdd30030f1c402da9b0d9563b.tar.gz
rails-50e6b69018ca4dfcdd30030f1c402da9b0d9563b.tar.bz2
rails-50e6b69018ca4dfcdd30030f1c402da9b0d9563b.zip
extract conditional to the caller
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb24
1 files changed, 13 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index 650f3a986a..060e3f3811 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -213,32 +213,34 @@ module ActiveRecord
parent.children.each do |node|
primary_id = type_caster.type_cast row[primary_key]
if ar_parent.id == primary_id
+ if node.reflection.collection?
+ other = ar_parent.association(node.reflection.name)
+ other.loaded!
+ end
+
+ next if row[node.aliased_primary_key].nil?
+
model = construct_model(ar_parent, node, row)
- construct(model, node, row, rs) if model
+ construct(model, node, row, rs)
end
end
end
def construct_model(record, join_part, row)
if join_part.reflection.collection?
- model = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
+ model = join_part.instantiate(row)
other = record.association(join_part.reflection.name)
- other.loaded!
other.target.push(model) if 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) unless row[join_part.aliased_primary_key].nil?
- set_target_and_inverse(join_part, model, record)
+ model = join_part.instantiate(row)
+ other = record.association(join_part.reflection.name)
+ other.target = model
+ other.set_inverse_instance(model)
end
model
end
-
- def set_target_and_inverse(join_part, model, record)
- other = record.association(join_part.reflection.name)
- other.target = model
- other.set_inverse_instance(model)
- end
end
end
end