From 2ee130abec222342c6f7ade3b651840dc89c1bcd Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 16 Jan 2010 03:50:51 +0530 Subject: [PATCH] Remove scope related code from construct_join --- activerecord/lib/active_record/base.rb | 26 +++++-------------- .../lib/active_record/calculations.rb | 2 +- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ab78248608927..6b4a1d007165a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1593,17 +1593,16 @@ def construct_finder_arel(options = {}, scope = nil) relation end - def construct_join(joins, scope) - merged_joins = scope && scope[:joins] && joins ? merge_joins(scope[:joins], joins) : (joins || scope && scope[:joins]) - case merged_joins + def construct_join(joins) + case joins when Symbol, Hash, Array - if array_of_strings?(merged_joins) - merged_joins.join(' ') + " " + if array_of_strings?(joins) + joins.join(' ') + " " else - build_association_joins(merged_joins) + build_association_joins(joins) end when String - " #{merged_joins} " + " #{joins} " else "" end @@ -1614,19 +1613,6 @@ def merge_includes(first, second) (Array.wrap(first) + Array.wrap(second)).uniq end - def merge_joins(*joins) - if joins.any?{|j| j.is_a?(String) || array_of_strings?(j) } - joins = joins.collect do |join| - join = [join] if join.is_a?(String) - join = build_association_joins(join) unless array_of_strings?(join) - join - end - joins.flatten.map{|j| j.strip}.uniq - else - joins.collect{|j| Array.wrap(j)}.flatten.uniq - end - end - def build_association_joins(joins) join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, joins, nil) relation = active_relation.table diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index bbb5922e0e8d0..cd7bd185c527e 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -160,7 +160,7 @@ def construct_calculation_arel(options = {}, merge_with_relation = nil) if includes.any? merge_with_joins = merge_with_relation ? merge_with_relation.joins_values : [] joins = (merge_with_joins + Array.wrap(options[:joins])).uniq - join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(joins, nil)) + join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(joins)) construct_calculation_arel_with_included_associations(options, join_dependency, merge_with_relation) else relation = active_relation.