0

これが機能しない理由はわかりませんが、結果が得られません。AContactには がたくさんありOrganizationContactsます。ブールOrganizationContactフィールドがありますprimary。以下に示すように、このフィールドにフィルターを追加しました。

class Contact < ActiveRecord::Base

  has_many :organization_contacts, :dependent => :destroy

  define_index do
    has organization_contacts(:primary), :as => :primary_contacts

    set_property :delta => true
  end
end

デバッグセッションでは、次のようにリストされているContactを実際に持っていることがわかります。OrganizationContactprimary

(rdb:1) p Contact.first.organization_contacts.first.primary
true

しかし、ThinkingSphinxそのフィルターを使用して検索を行うと、何も得られません。

(rdb:1) p Contact.search :with => { :primary_contacts => true }
[]

誰でも説明できますか?

4

1 に答える 1

0

コオロギの鳴き声。残念ながら、私たちは回避策を考え出しました。

class Contact < ActiveRecord::Base

  has_many :primary_organization_contacts, :class_name => "OrganizationContact", :foreign_key => "contact_id", :conditions => { :primary => true }
  has_many :organization_contacts, :dependent => :destroy

  define_index do
    has primary_organization_contacts(:id), :as => :primary_organization_contacts

    set_property :delta => true
  end
end

それらを探すのが面白い部分です。主要な組織の連絡先がないレコードが必要な場合:

Contact.search :with { :primary_organization_contacts => 0 }

少なくとも 1 つの主要な組織の連絡先を含むレコードが必要な場合:

Contact.search :without { :primary_organization_contacts => 0 }

それは私を汚く混乱させますが、それは仕事をします.

于 2012-11-14T21:22:29.147 に答える