From d75a0ef0d5139348b7b4d046374502824254a076 Mon Sep 17 00:00:00 2001 From: Joel Bryan Juliano Date: Mon, 31 Oct 2011 00:42:22 -0500 Subject: Added a failing test for a non-table alias as rhs relation name --- test/test_select_manager.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- cgit v1.2.3