Skip to content

Commit

Permalink
cache the primary key / typcast lookup on the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 11, 2013
1 parent 32fcdb3 commit 3a8892a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions activerecord/lib/active_record/associations/join_dependency.rb
Expand Up @@ -207,19 +207,19 @@ def build_join_association(reflection, parent, join_type)
end

def construct(ar_parent, parent, row, rs)
parent.children.each do |node|
association = construct_association(ar_parent, parent, node, row, rs)
construct(association, node, row, rs) if association
end
end

def construct_association(record, parent, join_part, row, rs)
primary_key = parent.aliased_primary_key
type_caster = rs.column_type primary_key
primary_id = type_caster.type_cast row[parent.aliased_primary_key]

return if record.id != primary_id
parent.children.each do |node|
primary_id = type_caster.type_cast row[primary_key]
if ar_parent.id == primary_id
association = construct_association(ar_parent, node, row)
construct(association, node, row, rs) if association
end
end
end

def construct_association(record, join_part, row)
macro = join_part.reflection.macro
if macro == :has_one
return record.association(join_part.reflection.name).target if record.association_cache.key?(join_part.reflection.name)
Expand Down

0 comments on commit 3a8892a

Please sign in to comment.