Skip to content
Browse files

remove useless code

turns out that the activerecord object will always have the same id as
the row from which it was constructed
  • Loading branch information...
1 parent b69b9de commit d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734 @tenderlove tenderlove committed Oct 11, 2013
Showing with 20 additions and 24 deletions.
  1. +20 −24 activerecord/lib/active_record/associations/join_dependency.rb
View
44 activerecord/lib/active_record/associations/join_dependency.rb
@@ -92,9 +92,9 @@ def columns
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 @@ def build_join_association(reflection, parent, join_type)
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

0 comments on commit d7ddaa5

Please sign in to comment.
Something went wrong with that request. Please try again.