好的,我有一个Node模型,它有以下关联:
class Node < ActiveRecord::Base
belongs_to :family_tree
belongs_to :user
belongs_to :media, polymorphic: true, dependent: :destroy
has_many :comments, dependent: :destroy
end关键关联是media关联,它实际上是Video的关联。这就是我的Video模型的样子:
class Video < ActiveRecord::Base
has_one :node, as: :media
end但我不太清楚如何在我的pg_search_scope中指定这一点。
我试过这样做:
include PgSearch
pg_search_scope :node_search, against: [:name, :user_id, :circa, :cached_user_tag_list, :cached_tagged_user_names],
using: { tsearch: { any_word: true, dictionary: :english, prefix: true} },
:associated_against => {
video: [:description, :title]
}但我得到的错误是:
Completed 500 Internal Server Error in 131ms (ActiveRecord: 41.6ms)
NoMethodError - undefined method `table_name' for nil:NilClass:所以当我这样做的时候:
include PgSearch
pg_search_scope :node_search, against: [:name, :user_id, :circa, :cached_user_tag_list, :cached_tagged_user_names],
using: { tsearch: { any_word: true, dictionary: :english, prefix: true} },
:associated_against => {
media: [:description, :title]
}我知道这个错误:
Completed 500 Internal Server Error in 126ms (ActiveRecord: 17.7ms)
NameError - uninitialized constant Node::Media:我如何指定这个关联,或者这是一个pg_search不知道如何管理的edgecase?
发布于 2015-07-30 15:25:35
pg_search的维护者提到,不能通过SQL直接搜索多态关联,因此pg_search - https://stackoverflow.com/a/15455017不可用。
https://stackoverflow.com/questions/31621162
复制相似问题