Search code examples
ruby-on-railssearchsearchkick

WARNING: calling search on a relation is deprecated


I keep getting this error when we upgraded our codebase to searchkick 4.4. I have tried to search online but to no avail.

So we have an Opportunity Model where we're calling search on a collection of ActiveRecord objects like so to return our search results:

results = r.search q, fields: [:search_term], match: :word_middle, order: { created_at: :desc}

r is the said collection we're calling search on. Is this the reason why this error is throwing? if it is, how do i go around it, we're doing a lot conditional checks and queries on the queries before we run the search.


Solution

  • Yes, that's exactly the reason why you see this warning. There will not be option to search on relation in next major version. It's breaking change so you need to update your code to follow where section if you are going to update the gem to higher version in the future. You simply need to translate your relation to be included in where part.