Skip to content

Instantly share code, notes, and snippets.

@DNA
Created October 28, 2021 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNA/b953f7b4619d9f38577cf22049629a29 to your computer and use it in GitHub Desktop.
Save DNA/b953f7b4619d9f38577cf22049629a29 to your computer and use it in GitHub Desktop.
Fix Rails SQL Server Adapter when using Arel::Nodes::TableAlias
# frozen_string_literal: true
module Arel
module Visitors
class SQLServer < Arel::Visitors::ToSql
def table_From_Statement o
core = o.cores.first
table_From_Node(core.from) || table_From_Node(core.source)
end
def table_From_Node n
case n
when Arel::Table then n
when Arel::Nodes::TableAlias then n
when Arel::Nodes::SqlLiteral then Arel::Table.new(n)
when Arel::Nodes::JoinSource then table_From_Node(n.left) || table_From_Node(n.right)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment