camertron / scuttle-server

Server behind scuttle.io, a SQL editor and Arel converter.
148 stars 10 forks source link

Can't handle aliased joins #13

Open singpolyma-shopify opened 5 years ago

singpolyma-shopify commented 5 years ago
SELECT c1.* FROM configurations c1 LEFT OUTER JOIN configurations c2 on c1.thing = c2.otherthing

Gives


Configuration.select(C1.arel_table[Arel.star]).joins(
  Configuration.arel_table.join(Configuration.arel_table, Arel::Nodes::OuterJoin).on(
    C1.arel_table[:thing].eq(C2.arel_table[:otherthing])
  ).join_sources
)

Assuming that C1 and C2 are tables when they're actually two aliases of the two sides of a self-join.

camertron commented 5 years ago

Hey @singpolyma-shopify, thanks for the bug report. I don't really have time to work on this right now, but would gladly accept a pull request :)