Skip to content
Browse files

reduce duplication in assiciations #construct()

  • Loading branch information...
1 parent 46332e4 commit 1acc086278c974d7a3cdb0459cd65f73641abe33 @tenderlove tenderlove committed
Showing with 3 additions and 9 deletions.
  1. +3 −9 activerecord/lib/active_record/associations.rb
View
12 activerecord/lib/active_record/associations.rb
@@ -1983,10 +1983,10 @@ def build_join_association(reflection, parent)
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 @@ def construct(parent, associations, join_parts, row)
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

0 comments on commit 1acc086

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