Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

extract the string handling part to a method.

We know the structure passed in to the `construct` method will be a
hash, so we don't need to test it all the time.  The key value will be a
symbol or string, so handle it with the special method
  • Loading branch information...
commit d2d6e4a980800cefce4066724ddd541ae22730c1 1 parent 77e5c12
@tenderlove tenderlove authored
Showing with 15 additions and 15 deletions.
  1. +15 −15 activerecord/lib/active_record/associations/join_dependency.rb
View
30 activerecord/lib/active_record/associations/join_dependency.rb
@@ -182,24 +182,24 @@ def build_join_association(reflection, parent, join_type)
end
def construct(parent, associations, join_parts, row)
- case associations
- when Symbol, String
- name = associations.to_s
+ associations.sort_by { |k,_| k.to_s }.each do |association_name, assoc|
+ association = construct_scalar(parent, association_name, join_parts, row)
+ construct(association, assoc, join_parts, row) if association
+ end
+ end
- join_part = join_parts.detect { |j|
- j.reflection.name.to_s == name &&
- j.parent_table_name == parent.class.table_name }
+ def construct_scalar(parent, associations, join_parts, row)
+ name = associations.to_s
- raise(ConfigurationError, "No such association") unless join_part
+ join_part = join_parts.detect { |j|
+ j.reflection.name.to_s == name &&
+ j.parent_table_name == parent.class.table_name
+ }
- join_parts.delete(join_part)
- construct_association(parent, join_part, row)
- when Hash
- associations.sort_by { |k,_| k.to_s }.each do |association_name, assoc|
- association = construct(parent, association_name, join_parts, row)
- construct(association, assoc, join_parts, row) if association
- end
- end
+ raise(ConfigurationError, "No such association") unless join_part
+
+ join_parts.delete(join_part)
+ construct_association(parent, join_part, row)
end
def construct_association(record, join_part, row)
Please sign in to comment.
Something went wrong with that request. Please try again.