diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 18:58:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 18:58:29 -0700 |
commit | d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734 (patch) | |
tree | f4d18da05d76a3457fcf4cb1690d4bb04d12daf2 /activerecord/lib/active_record | |
parent | b69b9de4bdd2d40334d4b1284d872f96a600789a (diff) | |
download | rails-d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734.tar.gz rails-d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734.tar.bz2 rails-d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734.zip |
remove useless code
turns out that the activerecord object will always have the same id as
the row from which it was constructed
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index b147f0a847..e40466c647 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -92,9 +92,9 @@ module ActiveRecord end def instantiate(result_set) - primary_key = join_root.aliased_primary_key parents = {} + primary_key = join_root.aliased_primary_key type_caster = result_set.column_type primary_key seen = Hash.new { |h,parent_klass| @@ -185,35 +185,31 @@ module ActiveRecord end def construct(ar_parent, parent, row, rs, seen) - primary_key = parent.aliased_primary_key - type_caster = rs.column_type primary_key + primary_id = ar_parent.id 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! - else - if ar_parent.association_cache.key?(node.reflection.name) - model = ar_parent.association(node.reflection.name).target - construct(model, node, row, rs, seen) - next - end + 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, seen) + next end + end - id = row[node.aliased_primary_key] - next if id.nil? + id = row[node.aliased_primary_key] + next if id.nil? - model = seen[parent.base_klass][primary_id][node.base_klass][id] + model = seen[parent.base_klass][primary_id][node.base_klass][id] - if model - construct(model, node, row, rs, seen) - else - model = construct_model(ar_parent, node, row) - seen[parent.base_klass][primary_id][node.base_klass][id] = model - construct(model, node, row, rs, seen) - end + if model + construct(model, node, row, rs, seen) + else + model = construct_model(ar_parent, node, row) + seen[parent.base_klass][primary_id][node.base_klass][id] = model + construct(model, node, row, rs, seen) end end end |