pg_search with acts_as_taggable_on and nested association

Viewed 4

here is my configuration


class Event < ApplicationRecord
  include PgSearch::Model

  belongs_to :establishment

  acts_as_taggable_on :mentions

  DEFAULT_FULLTEXT_SEARCH_OPTIONS =
    { ignoring: :accents,
      using: {
        tsearch: { prefix: true,
                   any_word: true,
                   negation: true },
        trigram: {}
      } }

  pg_search_scope :search_for, lambda { |name_part, query, associations = {}|
      options = DEFAULT_FULLTEXT_SEARCH_OPTIONS
      options[:associated_against] = associations if associations&.is_a?(Hash)
      {
        against: name_part,
        query: query
      }.merge(options)
    }
end

class Establishment < ApplicationRecord
  include PgSearch::Model

  acts_as_taggable_on :hashtags
end

From the Event, I would like to search on hashtags of the Establishment.

Here is my query:

Event.search_for([], "esta", {establishment: :hashtags})
# => ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column establishments.hashtags does not exist) 

I'm not sure this double nested association search is possible.

0 Answers
Related