Skip to content

pass table and column to custom sql function #20

@twelve17

Description

@twelve17

In trying to figure out some NULL sorting handling issues, I ran into #10, and in particular the suggestion to use COALESCE to turn a null value to a non-value.

In order to allow this kind of functionality for dynamic queries, I am suggesting that the table and column name obtained from the connection be passed to the sql function. In other words, in here, a change along the lines of:

          table = connection.quote_table_name(scope.table_name)
          column = connection.quote_column_name(column.name)

          if sql
            sql.respond_to?(:call) ? sql.call(table, column) : sql
          else
            "#{table}."\
            "#{column}"

This allows me to call COALESCE using the resolved table name, as I don't have access to the connection in the custom sql proc.

If you're open to this, I can submit a PR.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions