diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-30 09:54:23 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-30 09:54:23 -0700 |
commit | e8563a6234b4f60f8d756d89b3b35026a467694e (patch) | |
tree | f421b271d969036315b516f75555c32b4a218fe9 | |
parent | ff1718142c29d6373d07c108a9ea85a96d4ec62f (diff) | |
download | rails-e8563a6234b4f60f8d756d89b3b35026a467694e.tar.gz rails-e8563a6234b4f60f8d756d89b3b35026a467694e.tar.bz2 rails-e8563a6234b4f60f8d756d89b3b35026a467694e.zip |
use TableAlias nodes for aliasing subselects
-rw-r--r-- | lib/arel/factory_methods.rb | 4 | ||||
-rw-r--r-- | lib/arel/select_manager.rb | 2 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 2 | ||||
-rw-r--r-- | test/test_select_manager.rb | 2 |
4 files changed, 7 insertions, 3 deletions
diff --git a/lib/arel/factory_methods.rb b/lib/arel/factory_methods.rb index 09b82c0555..2ced1f8971 100644 --- a/lib/arel/factory_methods.rb +++ b/lib/arel/factory_methods.rb @@ -2,6 +2,10 @@ module Arel ### # Methods for creating various nodes module FactoryMethods + def create_table_alias relation, name + Nodes::TableAlias.new(relation, name) + end + def create_join to, constraint = nil, klass = Nodes::InnerJoin klass.new(to, constraint) end diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index de68b25b64..904a24bbb3 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -39,7 +39,7 @@ module Arel end def as other - Nodes::As.new grouping(@ast), Nodes::SqlLiteral.new(other) + create_table_alias grouping(@ast), Nodes::SqlLiteral.new(other) end def where_clauses diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index bbb2c54655..d1175df2a0 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -396,7 +396,7 @@ key on UpdateManager using UpdateManager#key= end def quote_table_name name - @quoted_tables[name] ||= @connection.quote_table_name(name) + @quoted_tables[name] ||= Arel::Nodes::SqlLiteral === name ? name : @connection.quote_table_name(name) end def quote_column_name name diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 7f276d071f..81a32e4490 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -131,7 +131,7 @@ module Arel manager1.from(as) manager1.to_sql.must_be_like %{ - SELECT lol FROM (SELECT * FROM "users" ) AS omg + SELECT lol FROM (SELECT * FROM "users" ) omg } end end |