Query with_deleted records using pg_search and associated_against

58 Views Asked by At

In my project, I have a model called Log that tracks all activities performed on an Item. Item can be soft deleted (using acts_as_paranoid gem). I implemented full-text search using pg_search to be able to search for logs that is associated to an item with a given title

Current log.rb

class Log < ApplicationRecord
  include PgSearch::Model

  # associations
  belongs_to :item

  # scopes
  pg_search_scope :search_log, associated_against: { item: %i[title] }, using: { tsearch: { prefix: true } }
  scope :list_feed, lambda { |search_text = nil|
    logs = all
    logs = logs.search_log(search_text) if search_text.present?
    logs
  }
end

This works well for Item that is not soft deleted, but now I want pg_search_scope to also be able to included soft deleted Item.

How do I go about doing that?

1

There are 1 best solutions below

0
On

You need to disable the paranoia default scope on Item, use unscoped in your query.