Question

I tried all combinations that I could find online and it always fails.

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

and

Match belongs_to :profile

Inside the Profile model I try to do:

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

  end
Était-ce utile?

La solution

Inspired by the blog post that Olivier linked to and confirmed in the Sunspot documentation, you could do:

# In your Profile model
searchable :if => proc { |profile| profile.match.present? } do
  integer :id
  string :country
  string :state
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top