提交 4e823b61 编写于 作者: A Aaron Patterson

guarantee a list in the alias tracker so we can remove a conditional

上级 494a26d7
......@@ -8,8 +8,8 @@ class AliasTracker # :nodoc:
attr_reader :aliases, :connection
# table_joins is an array of arel joins which might conflict with the aliases we assign here
def initialize(connection, table_joins = [])
@aliases = Hash.new { |h,k| h[k] = initial_count_for(k, table_joins) }
def initialize(connection, table_joins)
@aliases = Hash.new { |h,k| h[k] = initial_count_for(k, table_joins) }
@connection = connection
end
......@@ -46,8 +46,6 @@ def aliased_name_for(table_name, aliased_name)
private
def initial_count_for(name, table_joins)
return 0 if Arel::Table === table_joins
# quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase
quoted_name = connection.quote_table_name(name).downcase
......
......@@ -12,7 +12,7 @@ def scope(association, connection)
reflection = association.reflection
scope = klass.unscoped
owner = association.owner
alias_tracker = AliasTracker.new connection
alias_tracker = AliasTracker.new(connection, [])
scope.extending! Array(reflection.options[:extend])
add_constraints(scope, owner, klass, reflection, alias_tracker)
......
......@@ -347,7 +347,15 @@ def construct_join_dependency(joins = [])
end
def construct_relation_for_association_calculations
apply_join_dependency(self, construct_join_dependency(arel.froms.first))
from = arel.froms.first
if Arel::Table === from
apply_join_dependency(self, construct_join_dependency)
else
# FIXME: as far as I can tell, `from` will always be an Arel::Table.
# There are no tests that test this branch, but presumably it's
# possible for `from` to be a list?
apply_join_dependency(self, construct_join_dependency(from))
end
end
def apply_join_dependency(relation, join_dependency)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册