diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 11:44:04 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 11:44:04 -0700 |
commit | 3a8892aae21c624ca6daf1c02188f361491de270 (patch) | |
tree | cc1c32ee81ad487e00ce78c4e012634f00179ec2 /activerecord/lib/active_record | |
parent | 32fcdb3b9e95669ca024285364f96b083135ee82 (diff) | |
download | rails-3a8892aae21c624ca6daf1c02188f361491de270.tar.gz rails-3a8892aae21c624ca6daf1c02188f361491de270.tar.bz2 rails-3a8892aae21c624ca6daf1c02188f361491de270.zip |
cache the primary key / typcast lookup on the stack
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 48d8144017..d61e209e55 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -207,19 +207,19 @@ module ActiveRecord 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) |