diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-14 12:34:04 -0800 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2010-12-16 01:49:29 +0530 |
commit | b68407f7f013ce3b08d1273ac3c2ffd7a8a510c9 (patch) | |
tree | 1d73a55a279313f408c8279abe09eeecd0272ac2 /activerecord/lib | |
parent | c02fd2acc575f3e90da12d4915390a80a48b7c8e (diff) | |
download | rails-b68407f7f013ce3b08d1273ac3c2ffd7a8a510c9.tar.gz rails-b68407f7f013ce3b08d1273ac3c2ffd7a8a510c9.tar.bz2 rails-b68407f7f013ce3b08d1273ac3c2ffd7a8a510c9.zip |
bucketing based on join type
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 67a94cec85..ef14f48a8f 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -239,16 +239,25 @@ module ActiveRecord end def build_joins(manager, joins) - joins = joins.map {|j| j.respond_to?(:strip) ? j.strip : j}.uniq - - association_joins = joins.find_all do |join| - [Hash, Array, Symbol].include?(join.class) && !array_of_strings?(join) + buckets = joins.group_by do |join| + case join + when String + 'string_join' + when Hash, Symbol, Array + 'association_join' + when ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation + 'stashed_join' + else + raise 'unknown class: %s' % join.class.name + end end - stashed_association_joins = joins.grep(ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation) - - non_association_joins = (joins - association_joins - stashed_association_joins) - join_list = custom_join_ast(manager, non_association_joins) + association_joins = buckets['association_join'] || [] + stashed_association_joins = buckets['stashed_join'] || [] + string_joins = (buckets['string_join'] || []).map { |x| + x.strip + }.uniq + join_list = custom_join_ast(manager, string_joins) join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, join_list) |