Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Derived/Dynamic Columns #424

Open
jonmchan opened this issue Mar 19, 2024 · 1 comment
Open

Support for Derived/Dynamic Columns #424

jonmchan opened this issue Mar 19, 2024 · 1 comment

Comments

@jonmchan
Copy link

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.

@jonmchan
Copy link
Author

jonmchan commented Mar 20, 2024

After examining the code, I have my doubts if searchable: false was ever implemented. I couldn't find a test for it. I'm going to take a stab and see what I can do with it.

searchable: false works, I did add more tests to test it and understand its functionality. These tests may be helpful to make sure searchable: false does not regress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant