diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-07 18:54:04 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-07 18:54:04 -0800 |
commit | 1d96d44da318faab8d213f330aebcecdbec52f5d (patch) | |
tree | f4353bb7f8c9f2de7f846687122afdfeaa13fe02 /activerecord/lib | |
parent | d98cb5153dad97cde82ec91a1993043cfa9bc0e4 (diff) | |
download | rails-1d96d44da318faab8d213f330aebcecdbec52f5d.tar.gz rails-1d96d44da318faab8d213f330aebcecdbec52f5d.tar.bz2 rails-1d96d44da318faab8d213f330aebcecdbec52f5d.zip |
passing the ast to a table when the relation is a table
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/class_methods/join_dependency.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 23 |
2 files changed, 20 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb index 928e8152a5..d508c3b7aa 100644 --- a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb +++ b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb @@ -47,8 +47,6 @@ module ActiveRecord def count_aliases_from_table_joins(name) 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::Nodes::Join).map { |join| right = join.right case right diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 194ce881e0..df41f756ce 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -185,18 +185,30 @@ module ActiveRecord arel.join_sql end - def custom_join_ast(joins) + def custom_join_ast(table, joins) joins = joins.reject { |join| join.blank? } return if joins.empty? @implicit_readonly = true + joins.map! do |join| + case join + when Array + join = Arel.sql(join.join(' ')) if array_of_strings?(join) + when String + join = Arel.sql(join) + end + join + end + head = table.create_string_join(table, joins.shift) joins.inject(head) do |ast, join| ast.right = table.create_string_join(ast.right, join) end + + head end def build_arel @@ -269,8 +281,9 @@ module ActiveRecord non_association_joins = (joins - association_joins - stashed_association_joins) custom_joins = custom_join_sql(non_association_joins) + ast = custom_join_ast(relation, non_association_joins) - join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_join_ast(non_association_joins)) + join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, ast) join_dependency.graft(*stashed_association_joins) @@ -280,7 +293,11 @@ module ActiveRecord relation = association.join_to(relation) end - relation.join(custom_joins) + if Arel::Table === relation + relation.from(ast || relation) + else + relation.join(custom_joins) + end end def build_select(arel, selects) |