3

我尝试了所有可以在网上找到的组合,但总是失败。

class Profile < ActiveRecord::Base

  belongs_to  :user, :dependent => :destroy
  has_one     :match # educational matches 

  accepts_nested_attributes_for :match
  attr_accessor                 :form

  unless match.present?
    searchable do

      integer :id
      string :country
      string :state
    end
  end
end

Match belongs_to :profile

在 Profile 模型中,我尝试执行以下操作:

  unless profile.match.exist? (does profile have a match association existing?) 
    .. do something

  end
4

1 回答 1

2

受Olivier 链接并在 Sunspot 文档中确认的博客文章的启发,您可以执行以下操作:

# In your Profile model
searchable :if => proc { |profile| profile.match.present? } do
  integer :id
  string :country
  string :state
end
于 2013-10-26T15:49:09.080 回答