mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
JoinDependency is always created with an AST now
This commit is contained in:
@@ -49,10 +49,16 @@ module ActiveRecord
|
||||
|
||||
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)
|
||||
@table_joins.grep(Arel::Nodes::Join).map { |join|
|
||||
right = join.right
|
||||
case right
|
||||
when Arel::Table
|
||||
right.name.downcase == name ? 1 : 0
|
||||
when String
|
||||
count_aliases_from_string(right.downcase, name)
|
||||
else
|
||||
0
|
||||
end
|
||||
}.sum
|
||||
end
|
||||
|
||||
|
||||
@@ -185,6 +185,20 @@ module ActiveRecord
|
||||
arel.join_sql
|
||||
end
|
||||
|
||||
def custom_join_ast(joins)
|
||||
joins = joins.reject { |join| join.blank? }
|
||||
|
||||
return if joins.empty?
|
||||
|
||||
@implicit_readonly = true
|
||||
|
||||
head = table.create_string_join(table, joins.shift)
|
||||
|
||||
joins.inject(head) do |ast, join|
|
||||
ast.right = table.create_string_join(ast.right, join)
|
||||
end
|
||||
end
|
||||
|
||||
def build_arel
|
||||
arel = table
|
||||
|
||||
@@ -256,7 +270,7 @@ module ActiveRecord
|
||||
non_association_joins = (joins - association_joins - stashed_association_joins)
|
||||
custom_joins = custom_join_sql(non_association_joins)
|
||||
|
||||
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_joins)
|
||||
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_join_ast(non_association_joins))
|
||||
|
||||
join_dependency.graft(*stashed_association_joins)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user