From 1acc086278c974d7a3cdb0459cd65f73641abe33 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 6 Nov 2010 18:20:02 -0700 Subject: reduce duplication in assiciations #construct() --- activerecord/lib/active_record/associations.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index aad0cbb895..c84673e6a6 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1983,10 +1983,10 @@ module ActiveRecord def construct(parent, associations, join_parts, row) case associations when Symbol, String - associations = associations.to_s + name = associations.to_s join_part = join_parts.detect { |j| - j.reflection.name.to_s == associations && + j.reflection.name.to_s == name && j.parent_table_name == parent.class.table_name } raise(ConfigurationError, "No such association") unless join_part @@ -1999,13 +1999,7 @@ module ActiveRecord end when Hash associations.sort_by { |k,_| k.to_s }.each do |name, assoc| - join_part = join_parts.detect{ |j| - j.reflection.name.to_s == name.to_s && - j.parent_table_name == parent.class.table_name } - raise(ConfigurationError, "No such association") if join_part.nil? - - association = construct_association(parent, join_part, row) - join_parts.delete(join_part) + association = construct(parent, name, join_parts, row) construct(association, assoc, join_parts, row) if association end else -- cgit v1.2.3