Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何针对pg_搜索中具有`as:`名称的关联指定`associated_`?_Ruby On Rails_Ruby On Rails 4_Pg Search - Fatal编程技术网

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: