Permalink
Browse files

cache the primary key / typcast lookup on the stack

  • Loading branch information...
tenderlove committed Oct 11, 2013
1 parent 32fcdb3 commit 3a8892aae21c624ca6daf1c02188f361491de270
Showing with 9 additions and 9 deletions.
  1. +9 −9 activerecord/lib/active_record/associations/join_dependency.rb
@@ -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)

0 comments on commit 3a8892a

Please sign in to comment.