Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #90 from JoelJuliano/patch-1

Allow using non-table alias as a rhs relation name, fix for #84 and #59
  • Loading branch information...
commit 411336b86712df79016c2a4f36fe4e943546a185 2 parents 8ab89f5 + 2680d64
Aaron Patterson tenderlove authored
Showing with 18 additions and 1 deletion.
  1. +1 −1  lib/arel/nodes/table_alias.rb
  2. +17 −0 test/test_select_manager.rb
2  lib/arel/nodes/table_alias.rb
View
@@ -10,7 +10,7 @@ def [] name
end
def table_name
- relation.name
+ relation.respond_to?(:name) ? relation.name : name
end
end
end
17 test/test_select_manager.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.