aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/associations/alias_tracker.rb6
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb2
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb10
3 files changed, 12 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb
index f41f7bffff..ea8e1f5054 100644
--- a/activerecord/lib/active_record/associations/alias_tracker.rb
+++ b/activerecord/lib/active_record/associations/alias_tracker.rb
@@ -8,8 +8,8 @@ module ActiveRecord
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 @@ module ActiveRecord
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
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 1bc998d20c..63e81a17aa 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -12,7 +12,7 @@ module ActiveRecord
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)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 01d46f7676..7099bdd285 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -347,7 +347,15 @@ module ActiveRecord
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)