![](/img/trans.png)
[英]pg_search using associated_against gives error “column [model_name].[associated_column_name] does not exist”
[英]Query with_deleted records using pg_search and associated_against
在我的項目中,我有一個名為Log
的 model,它跟蹤對Item
執行的所有活動。 Item
可以被軟刪除(使用acts_as_paranoid
gem)。 我使用pg_search
實現了全文搜索,以便能夠搜索與具有給定title
的項目關聯的日志
當前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
這適用於未軟刪除的Item
,但現在我希望pg_search_scope
也能夠包含軟刪除的Item
。
我該怎么做 go?
您需要在Item
上禁用偏執狂默認值 scope,在查詢中使用unscoped
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.