我的模型有以下范围:
class Cloth < ActiveRecord::Base include Ownerable has_many :cloth_tags, :dependent => :destroy pg_search_scope :full_search, associated_against: { cloth_tags: [:name, :brand_name] }, against: [:name, :description], ignoring: :accents, using: { tsearch: { dictionary: "spanish", any_word: true } }因此,如果我调用类似Cloth.full_search('shirt')的方法工作正常,但是如果将owner: [:name]添加到associated_against哈希中,则会抛出NameError: uninitialized constant Cloth::Owner.无需多说,在正常情况下,所有者关系是有效的.无论如何都是在这样的模块中定义的:
So if I call something like Cloth.full_search('shirt') works fine, but if I add owner: [:name] to the associated_against hash, it throws NameError: uninitialized constant Cloth::Owner. Nedless to say that the owner relationship in normal circumstances is working. In any case is defined in a module like this:
module Ownerable extend ActiveSupport::Concern included do belongs_to :owner, :polymorphic => true end任何线索可能是什么?预先感谢
Any clue what thing could be? Thanks in advance
推荐答案我是pg_search的作者和维护者.
I'm the author and maintainer of pg_search.
不幸的是,在纯SQL中不可能朝这个方向遍历多态关联,因此使用pg_search进行搜索是不可能的.
Unfortunately, it's not possible to traverse a polymorphic association in this direction in pure SQL, so doing that search is not possible with pg_search.
您可以做的一件事是从其他记录中计算文本并将其缓存到Cloth表的一列中,然后搜索该文本.每当Cloth上的多态外键更改或Owner记录中的内容更改时,您都必须小心进行更新.
One thing you could do is calculate the text from the other records and cache it to a column on the Cloth table, then search against that instead. You'd have to be careful to update it whenever either the polymorphic foreign key changes on Cloth or the content changes on the Owner record.
希望我可以改善错误消息,以免造成混乱.感谢您指出这一点.
Hopefully I can improve the error message so that it's not so confusing. Thanks for pointing this out.
更多推荐
将pg
发布评论