提交 2d9d6cd4 编写于 作者: A Aaron Patterson

passing the ast to JoinDependency

上级 d6133209
......@@ -45,11 +45,20 @@ def columns
end
def count_aliases_from_table_joins(name)
return 0 unless @table_joins
return 0 if !@table_joins || Arel::Table === @table_joins
return count_aliases_from_string(@table_joins.downcase, name) if String === @table_joins
@table_joins.grep(Arel::Table).find_all { |table|
table.name.downcase == name
}.length + @table_joins.grep(String).map { |s|
count_aliases_from_string(s, name)
}.sum
end
def count_aliases_from_string(join_sql, name)
# quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase
quoted_name = active_record.connection.quote_table_name(name.downcase).downcase
join_sql = @table_joins.downcase
# Table names
join_sql.scan(/join(?:\s+\w+)?\s+#{quoted_name}\son/).size +
# Table aliases
......
......@@ -196,7 +196,7 @@ def find_with_associations
def construct_relation_for_association_calculations
including = (@eager_load_values + @includes_values).uniq
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, arel.join_sql)
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, arel.froms.first)
relation = except(:includes, :eager_load, :preload)
apply_join_dependency(relation, join_dependency)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册