I'm running into a situation where I need to swap out an underlying join table 
of an association. The way I'm doing this is specifying a a join table of 
:bar___baz  where 'baz' is the natural name and 'bar' is the table I'm swapping 
in. Long story short... it boils down to a call like this:

>> Sequel::Model.db[:foo].join_table(:inner, :bar___baz, {1 => 1}, 
>> {:table_alias => :baz})
=> #<Sequel::JDBC::MSSQL::Dataset: "SELECT * FROM [foo] INNER JOIN [bar] AS 
[baz] AS [baz] ON (1 = 1)">

The table is aliased twice as 'baz'. This short patch seems to fix the problem 
and doesn't break any tests AFAIK

--- a/lib/sequel/dataset/sql.rb
+++ b/lib/sequel/dataset/sql.rb
@@ -320,7 +320,7 @@ module Sequel
     def join_clause_sql(jc)
       table = jc.table
       table_alias = jc.table_alias
-      table_alias = nil if table == table_alias
+      table_alias = nil if table == table_alias || (table.is_a?(Symbol) && 
split_symbol(table)[2] == table_alias)
       tref = table_ref(table)
       " #{join_type_sql(jc.join_type)} #{table_alias ? as_sql(tref, 
table_alias) : tref}"
     end


gist link incase formatting is garbled...
http://gist.github.com/546348

can anyone think of a better solution for this problem? (aside from stop doing 
all that silly association table swapping  :)

Cheers,
Mike


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to