pg_search icon indicating copy to clipboard operation
pg_search copied to clipboard

Adding dynamic for "associated against" option

Open krthi opened this issue 4 years ago • 2 comments

We are working with multi-tenant application and we are in need of having dynamic search fields based on the account preference.

Dynamic columns of the same model(against option) works well with the Dynamic search scopes. I tried the same for the associated against option and that is not working.

pg_search_scope :search_by_employee, lambda { |against, associated_against, query|
    {
      against: against,
      associated_against: associated_against
      query: query,
      using: { tsearch: { prefix: true }, trigram: { word_similarity: true, threshold: 0.3 } },
      ranked_by: ':trigram'
    }
  }

employees.search_by_employee(['first_name'], ["officer_statuses": ["name"]], params[:search_text])

I am getting below error for the above code,

PG::UndefinedTable - ERROR:  invalid reference to FROM-clause entry for table "employees"
LINE 1: ... AS rank FROM "employees" LEFT OUTER JOIN (SELECT "employees...
                                                             ^

Is there any way to make the associated against option dynamic?

krthi avatar May 12 '20 05:05 krthi

I am stuck on this too. Same error.

dcporter44 avatar May 13 '24 22:05 dcporter44

It's reproducible if the "employees" relation already joins "officer_statuses". If you get rid of the joins on the initial relation, it works. But in my case I need that initial joins.

dcporter44 avatar May 13 '24 23:05 dcporter44