Class: Sunspot::Rails::Adapters::ActiveResourceDataAccessor

Inherits:
Adapters::DataAccessor
  • Object
show all
Defined in:
lib/sunspot/rails/adapters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#includeObject

options for the find



98
99
100
# File 'lib/sunspot/rails/adapters.rb', line 98

def include
  @include
end

#selectObject

options for the find



98
99
100
# File 'lib/sunspot/rails/adapters.rb', line 98

def select
  @select
end

Instance Method Details

#load(id) ⇒ Object

Get one ActiveRecord instance out of the database by ID

Parameters

id<String>

Database ID of model to retreive

Returns

ActiveRecord::Base

ActiveRecord model



124
125
126
127
128
# File 'lib/sunspot/rails/adapters.rb', line 124

def load(id)
  @clazz.first(options_for_find.merge(
    :conditions => { @clazz.primary_key => id.to_i}
  ))
end

#load_all(ids) ⇒ Object

Get a collection of ActiveRecord instances out of the database by ID

Parameters

ids<Array>

Database IDs of models to retrieve

Returns

Array

Collection of ActiveRecord models



141
142
143
144
145
# File 'lib/sunspot/rails/adapters.rb', line 141

def load_all(ids)
  @clazz.find(:all, options_for_find.merge(
    :conditions => { @clazz.primary_key => ids.map { |id| id.to_i }}
  ))
end