Permalink
Browse files

Added a failing test for a non-table alias as rhs relation name

  • Loading branch information...
1 parent 45f8717 commit d75a0ef0d5139348b7b4d046374502824254a076 @JoelJuliano-duplicate JoelJuliano-duplicate committed Oct 31, 2011
Showing with 18 additions and 0 deletions.
  1. +18 −0 test/test_select_manager.rb
@@ -654,6 +654,24 @@ def test_join_sources
}
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

0 comments on commit d75a0ef

Please sign in to comment.