Skip to content

Commit

Permalink
Remove scope related code from construct_join
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Jan 15, 2010
1 parent 8908200 commit 2ee130a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
26 changes: 6 additions & 20 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/calculations.rb
Expand Up @@ -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.
Expand Down

0 comments on commit 2ee130a

Please sign in to comment.