Sha256: 763642fe9d51016b4842576632752a8d0d88c58b44dd6fc79ad1f273a2d5a482

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

module ThinkingSphinx
  module ActiveRecord
    module HasManyAssociation
      def search(*args)
        options   = args.extract_options!
        options[:with] ||= {}
        options[:with].merge! default_filter
        
        args << options
        @reflection.klass.search(*args)
      end

      private
      
      def attribute_for_foreign_key
        foreign_key = @reflection.primary_key_name
        stack = [@reflection.options[:through]].compact
        
        @reflection.klass.define_indexes
        (@reflection.klass.sphinx_indexes || []).each do |index|
          attribute = index.attributes.detect { |attrib|
            attrib.columns.length == 1 &&
            attrib.columns.first.__name  == foreign_key.to_sym ||
            attrib.alias == foreign_key.to_sym
          }
          return attribute unless attribute.nil?
        end
        
        raise "Missing Attribute for Foreign Key #{foreign_key}"
      end
      
      def default_filter
        {attribute_for_foreign_key.unique_name => @owner.id}
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
thinking-sphinx-2.0.12 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-1.4.12 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-2.0.11 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-1.4.11 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-2.0.10 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-1.4.10 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-2.0.9 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-1.4.9 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-2.0.8 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-1.4.8 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-2.0.7 lib/thinking_sphinx/active_record/has_many_association.rb
thinking-sphinx-1.4.7 lib/thinking_sphinx/active_record/has_many_association.rb