Module: SunspotAssociation::Model::ClassMethods
- Defined in:
- lib/sunspot_association/model.rb
Instance Method Summary collapse
- #reset_sunspot_associations! ⇒ Object
-
#sunspot_associate(*args) ⇒ Object
Reindex associations when a model changes.
- #sunspot_associate? ⇒ Boolean
Instance Method Details
#reset_sunspot_associations! ⇒ Object
62 63 64 |
# File 'lib/sunspot_association/model.rb', line 62 def reset_sunspot_associations! self.sunspot_association_configuration = {} end |
#sunspot_associate(*args) ⇒ Object
Reindex associations when a model changes
Options:
:fields => Field(s) to watch for changes
:on_create => Specifies if it should reindex associations when a record is created
Examples:
=> sunspot_associate :orders, :fields => :name => sunspot_associate :orders, :users, :fields => [:name, :phone], :on_create => true
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sunspot_association/model.rb', line 41 def sunspot_associate(*args) = args. fields = .delete(:fields) self.sunspot_association_configuration ||= {} args.each do |object| default = { :fields => [] } config = self.sunspot_association_configuration[object] || default # Fields config[:fields] += Array(fields) config[:fields].compact! config[:fields].uniq! config.merge!() self.sunspot_association_configuration[object] = config end end |
#sunspot_associate? ⇒ Boolean
22 23 24 |
# File 'lib/sunspot_association/model.rb', line 22 def sunspot_associate? self.sunspot_association_configuration.present? end |