lib/sunspot/rails/adapters.rb in sunspot_rails-2.2.3 vs lib/sunspot/rails/adapters.rb in sunspot_rails-2.2.4
- old
+ new
@@ -19,15 +19,16 @@
end
class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
# options for the find
attr_accessor :include
+ attr_accessor :scopes
attr_reader :select
def initialize(clazz)
super(clazz)
- @inherited_attributes = [:include, :select]
+ @inherited_attributes = [:include, :select, :scopes]
end
#
# Set the fields to select from the database. This will be passed
# to ActiveRecord.
@@ -75,9 +76,12 @@
def scope_for_load
scope = relation
scope = scope.includes(@include) if @include.present?
scope = scope.select(@select) if @select.present?
+ Array.wrap(@scopes).each do |s|
+ scope = scope.send(s)
+ end
scope
end
# COMPATIBILITY: Rails 4 has deprecated the 'scoped' method in favour of 'all'
def relation