Skip to content

Support for Derived/Dynamic Columns #424

Open
@jonmchan

Description

@jonmchan

I created a virtual or derived column with the following code:

  def view_columns
    # Declare strings in this format: ModelName.column_name
    # or in aliased_join_table.column_name format
    @view_columns ||= {
      ...
      br_baths: { source: 'Property.br_baths', searchable: false },
    }
  end

  def data
    records.map do |record|
      {
        ...
        br_baths: "#{record.bedrooms} BR/#{record.consolidated_bathrooms} Baths",
      }
    end
  end

The table shows up properly, however the search is broken because the Property.br_baths column does not exist.

This fails with error:

 ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column properties.br_baths does not exist

Is there any way to modify the query that is generated from search or make this field not searchable? I was expecting the searchable: false to prevent this field from being searched but it is not working. I could be mistaken, but I was noticing that there are no tests for searchable: false. It would seem that all the columns are being included in the search. This would be one solution, the other solution is to somehow generate custom SQL for this such that instead of searching br_baths, it was searching bedrooms and bathrooms indepedently.

Thank you for any support and feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions