diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 18:02:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 18:02:20 -0700 |
commit | d9a7f86666a8f4345fc2b4680ec9b407294a6cc0 (patch) | |
tree | 057c95abf35ee8429b66835e3b76edd40c9ae12e | |
parent | 8c155a656201a4b39a7b671bb27b081fa34f268b (diff) | |
download | rails-d9a7f86666a8f4345fc2b4680ec9b407294a6cc0.tar.gz rails-d9a7f86666a8f4345fc2b4680ec9b407294a6cc0.tar.bz2 rails-d9a7f86666a8f4345fc2b4680ec9b407294a6cc0.zip |
push up the loaded target checking
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 50bd2fbe8e..6457880e65 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -216,6 +216,12 @@ module ActiveRecord 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 @@ module ActiveRecord 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 |