Permalink
Browse files

Merge remote-tracking branch 'rails/master'

  • Loading branch information...
2 parents 4653755 + 411336b commit 7fc81c8ede91b77f8da3c8dcc0380095983ad678 @parndt parndt committed Nov 3, 2011
Showing with 18 additions and 1 deletion.
  1. +1 −1 lib/arel/nodes/table_alias.rb
  2. +17 −0 test/test_select_manager.rb
View
2 lib/arel/nodes/table_alias.rb
@@ -10,7 +10,7 @@ def [] name
end
def table_name
- relation.name
+ relation.respond_to?(:name) ? relation.name : name
end
end
end
View
17 test/test_select_manager.rb
@@ -654,6 +654,23 @@ 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 7fc81c8

Please sign in to comment.