On Aug 23, 2:14 pm, Mike Luu <[email protected]> wrote:
> 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  :)

Is there a reason you are using both an implicit table alias and an
explicit table alias?  I'm just curious.

I think the better solution would be to handle the situation inside
join_table, maybe by ignoring the explicit alias if there is an
implicit alias.  What do you think?

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to