Ruby on rails 如何针对pg_搜索中具有`as:`名称的关联指定`associated_`?
好的,我有一个Ruby on rails 如何针对pg_搜索中具有`as:`名称的关联指定`associated_`?,ruby-on-rails,ruby-on-rails-4,pg-search,Ruby On Rails,Ruby On Rails 4,Pg Search,好的,我有一个节点模型,它有以下关联: class Node < ActiveRecord::Base belongs_to :family_tree belongs_to :user belongs_to :media, polymorphic: true, dependent: :destroy has_many :comments, dependent: :destroy end 但是我不太明白如何在我的pg\u搜索范围中指定这一点 我试过这个: include
节点
模型,它有以下关联:
class Node < ActiveRecord::Base
belongs_to :family_tree
belongs_to :user
belongs_to :media, polymorphic: true, dependent: :destroy
has_many :comments, dependent: :destroy
end
但是我不太明白如何在我的pg\u搜索范围中指定这一点
我试过这个:
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_搜索不知道如何管理的边缘?pg_搜索的维护者提到,多态关联无法通过SQL直接搜索,因此无法用于pg_搜索-
Completed 500 Internal Server Error in 126ms (ActiveRecord: 17.7ms)
NameError - uninitialized constant Node::Media: