Skip to content

Commit

Permalink
reduce duplication in assiciations #construct()
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 7, 2010
1 parent 46332e4 commit 1acc086
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1acc086

Please sign in to comment.