lib/ctes_in_my_pg.rb
# WithChain objects act as placeholder for queries in which #with does not have any parameter.
# In this case, #with must be chained with #recursive to return a new relation.
WithChain objects act as placeholder for queries in which #with does not have any parameter.
In this case, #with must be chained with #recursive to return a new relation.
WithChain objects act as placeholder for queries in which #with does not have any parameter . In this case #with must be chained with #recursive to return a new relation .
def build_with(arel)
      with_statements = with_values.flat_map do |with_value|
        case with_value
        when String
          with_value
        when Hash
          with_value.map  do |name, expression|
            case expression
            when String
              select = Arel::Nodes::SqlLiteral.new "(#{expression})"
            when ActiveRecord::Relation, Arel::SelectManager
              select = Arel::Nodes::SqlLiteral.new "(#{expression.to_sql})"
            end
            Arel::Nodes::As.new Arel::Nodes::SqlLiteral.new(PG::Connection.quote_ident(name.to_s)), select
          end
        when Arel::Nodes::As
          with_value
        end
      end
      unless with_statements.empty?
        if recursive_value
          arel.with :recursive, with_statements
        else
          arel.with with_statements
        end
      end
    end
def build_with ( arel ) with_statements = with_values . flat_map do | with_value | case with_value when String with_value when Hash with_value . map do | name , expression | case expression when String select = Arel :: Nodes :: SqlLiteral . new "(#{expression})" when ActiveRecord :: Relation , Arel :: SelectManager select = Arel :: Nodes :: SqlLiteral . new "(#{expression.to_sql})" end Arel :: Nodes :: As . new Arel :: Nodes :: SqlLiteral . new ( PG :: Connection . quote_ident ( name . to_s ) ) , select end when Arel :: Nodes :: As with_value end end unless with_statements . empty? if recursive_value arel . with :recursive , with_statements else arel . with with_statements end end end
WithChain objects act as placeholder for queries in which #with does not have any parameter.
WithChain objects act as placeholder for queries in which #with does not have any parameter .
arel
<not_specific>