diff options
author | Philip Arndt <parndt@gmail.com> | 2011-11-03 17:21:34 +1300 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2011-11-03 17:21:34 +1300 |
commit | 7fc81c8ede91b77f8da3c8dcc0380095983ad678 (patch) | |
tree | 0e4dd32d601153077754ba46f037f0c192cb9098 /test/test_select_manager.rb | |
parent | 4653755ca28d49ef8215254c4de9da4bb6b888e6 (diff) | |
parent | 411336b86712df79016c2a4f36fe4e943546a185 (diff) | |
download | rails-7fc81c8ede91b77f8da3c8dcc0380095983ad678.tar.gz rails-7fc81c8ede91b77f8da3c8dcc0380095983ad678.tar.bz2 rails-7fc81c8ede91b77f8da3c8dcc0380095983ad678.zip |
Merge remote-tracking branch 'rails/master'
Diffstat (limited to 'test/test_select_manager.rb')
-rw-r--r-- | test/test_select_manager.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 7e9099d0d0..a00d1843ba 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -654,6 +654,23 @@ module Arel } end + it 'can have a non-table alias as relation name' do + users = Table.new :users + comments = Table.new :comments + + counts = comments.from(comments). + group(comments[:user_id]). + project( + comments[:user_id].as("user_id"), + comments[:user_id].count.as("count") + ).as("counts") + + joins = users.join(counts).on(counts[:user_id].eq(10)) + joins.to_sql.must_be_like %{ + SELECT FROM "users" INNER JOIN (SELECT "comments"."user_id" AS user_id, COUNT("comments"."user_id") AS count FROM "comments" GROUP BY "comments"."user_id") counts ON counts."user_id" = 10 + } + end + it 'returns string join sql' do table = Table.new :users manager = Arel::SelectManager.new Table.engine |