Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support AliasedExpressions in tables when using implicitly qualified …

…arguments in joins

This allows you to do:

  DB.from(:i.as(:j)).join(:k.as(:l), :a=>:b)
  #=> ... FROM i AS j INNER JOIN k AS l ON (l.a = j.b)
  • Loading branch information...
commit 4bbbedc717adf020e0e025bd0e0e967015cbcfef 1 parent 24d7901
Jeremy Evans authored
2  CHANGELOG
View
@@ -1,5 +1,7 @@
=== HEAD
+* Support AliasedExpressions in tables when using implicitly qualified arguments in joins (jeremyevans)
+
* Support Dataset#except on Oracle (jeremyevans)
* Raise errors when EXCEPT/INTERSECT is used when not supported (jeremyevans)
11 lib/sequel_core/dataset/sql.rb
View
@@ -846,9 +846,14 @@ def qualified_column_name(column, table)
if Symbol === column
c_table, column, c_alias = split_symbol(column)
unless c_table
- schema, table, t_alias = split_symbol(table) if Symbol === table
- t_alias = schema ? Sequel::SQL::QualifiedIdentifier.new(schema, table) : table unless t_alias
- c_table = t_alias
+ case table
+ when Symbol
+ schema, table, t_alias = split_symbol(table)
+ t_alias ||= Sequel::SQL::QualifiedIdentifier.new(schema, table) if schema
+ when Sequel::SQL::AliasedExpression
+ t_alias = table.aliaz
+ end
+ c_table = t_alias || table
end
::Sequel::SQL::QualifiedIdentifier.new(c_table, column)
else
5 spec/sequel_core/dataset_spec.rb
View
@@ -1321,6 +1321,11 @@ def fetch_rows(sql)
'SELECT * FROM "s"."t" AS "z" INNER JOIN "u"."v" AS "y" ON ("y"."id" = "z"."player_id")'
end
+ specify "should support AliasedExpressions" do
+ @d.from(:s.as(:t)).join(:u.as(:v), {:id => :player_id}).sql.should ==
+ 'SELECT * FROM "s" AS "t" INNER JOIN "u" AS "v" ON ("v"."id" = "t"."player_id")'
+ end
+
specify "should support the :implicit_qualifier option" do
@d.from('stats').join('players', {:id => :player_id}, :implicit_qualifier=>:p).sql.should ==
'SELECT * FROM "stats" INNER JOIN "players" ON ("players"."id" = "p"."player_id")'
Please sign in to comment.
Something went wrong with that request. Please try again.