Module: SearchApi::Integration::ActiveRecord::Associations::Find

Defined in:
lib/search_api/active_record_integration.rb

Overview

Module that holds integration of SearchApi::Search::Base into ActiveRecord::Associations::HasManyAssociation, ActiveRecord::Associations::HasAndBelongsToManyAssociation, and ActiveRecord::Associations::HasManyThroughAssociation.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object

:nodoc:



142
143
144
145
# File 'lib/search_api/active_record_integration.rb', line 142

def self.append_features(base) #:nodoc:
  super
  base.alias_method_chain(:find, :search_support)
end

Instance Method Details

#find_with_search_support(*args) ⇒ Object

Alteration of the :find method that has support for search keys added by the search method.



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/search_api/active_record_integration.rb', line 148

def find_with_search_support(*args)
  if @reflection.klass.respond_to?(:search_class)
    options = if args.last.is_a?(Hash) then args.last else {} end
    if options[:conditions].nil? || options[:conditions].is_a?(Hash)
      @reflection.klass.send(:with_scope, :find => @reflection.klass.search_class.new(options.delete(:conditions)).find_options) do
        find_without_search_support(*args)
      end
    else
      find_without_search_support(*args)
    end
  else
    find_without_search_support(*args)
  end
end