JoinDependency is always created with an AST now

This commit is contained in:
Aaron Patterson
2010-12-07 17:05:15 -08:00
parent 2d9d6cd4c2
commit d98cb5153d
2 changed files with 25 additions and 5 deletions

View File

@@ -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

View File

@@ -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)