diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-07 15:12:40 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-07 15:12:40 -0700 |
commit | d2d6e4a980800cefce4066724ddd541ae22730c1 (patch) | |
tree | 094f76bab3c03dbf5ef27b2c561d51bc402a696a /activerecord/lib | |
parent | 77e5c1262c7ef987cc0cdf3d246448dabc0b6e80 (diff) | |
download | rails-d2d6e4a980800cefce4066724ddd541ae22730c1.tar.gz rails-d2d6e4a980800cefce4066724ddd541ae22730c1.tar.bz2 rails-d2d6e4a980800cefce4066724ddd541ae22730c1.zip |
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
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 8b0e469a98..6d3b1b6b3b 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -182,24 +182,24 @@ module ActiveRecord 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) |