diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_select_manager.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 7e9099d0d0..ca47b873a2 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -654,6 +654,24 @@ 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 |