Permalink
Browse files

Make Dataset#join_table work with symbols with implicit schemas

Before, in order to handle implicit aliases, it would split the
symbol (and throw away the schema part).
  • Loading branch information...
1 parent 70aa14e commit 8b395139f67ddcf7f24443cb6c1d7460e409f639 @jeremyevans committed Nov 20, 2008
Showing with 17 additions and 2 deletions.
  1. +5 −2 lib/sequel_core/dataset/sql.rb
  2. +12 −0 spec/sequel_core/dataset_spec.rb
@@ -845,8 +845,11 @@ def join_type_sql(join_type)
def qualified_column_name(column, table)
if Symbol === column
c_table, column, c_alias = split_symbol(column)
- schema, table, t_alias = split_symbol(table) if Symbol === table
- c_table ||= t_alias || table
+ 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
+ end
::Sequel::SQL::QualifiedIdentifier.new(c_table, column)
else
column
@@ -1309,6 +1309,18 @@ def fetch_rows(sql)
'SELECT * FROM "foo" AS "f" INNER JOIN "bar" ON ("bar"."id" = "f"."bar_id")'
end
+ specify "should support implicit schemas in from table symbols" do
+ @d.from(:s__t).join(:u__v, {:id => :player_id}).sql.should ==
+ 'SELECT * FROM "s"."t" INNER JOIN "u"."v" ON ("u"."v"."id" = "s"."t"."player_id")'
+ end
+
+ specify "should support implicit aliases in from table symbols" do
+ @d.from(:t___z).join(:v___y, {:id => :player_id}).sql.should ==
+ 'SELECT * FROM "t" AS "z" INNER JOIN "v" AS "y" ON ("y"."id" = "z"."player_id")'
+ @d.from(:s__t___z).join(:u__v___y, {:id => :player_id}).sql.should ==
+ 'SELECT * FROM "s"."t" AS "z" INNER JOIN "u"."v" AS "y" ON ("y"."id" = "z"."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")'

0 comments on commit 8b39513

Please sign in to comment.