Class: Sunspot::Rails::Adapters::MongoidDataAccessor
- Inherits:
-
Adapters::DataAccessor
- Object
- Adapters::DataAccessor
- Sunspot::Rails::Adapters::MongoidDataAccessor
- Defined in:
- lib/sunspot/rails/adapters.rb
Instance Attribute Summary collapse
-
#select ⇒ Object
options for the find.
Instance Method Summary collapse
-
#load(id) ⇒ Object
Get one Mongoid document instance out of the database by ID.
-
#load_all(ids) ⇒ Object
Get a collection of Mongoid instances out of the database by ID.
Instance Attribute Details
#select ⇒ Object
options for the find
33 34 35 |
# File 'lib/sunspot/rails/adapters.rb', line 33 def select @select end |
Instance Method Details
#load(id) ⇒ Object
Get one Mongoid document instance out of the database by ID
Parameters
- id<String>
-
Database ID of model to retreive
Returns
Mongoid model
58 59 60 |
# File 'lib/sunspot/rails/adapters.rb', line 58 def load(id) @clazz.find(BSON::ObjectID.from_string(id)) rescue nil end |
#load_all(ids) ⇒ Object
Get a collection of Mongoid instances out of the database by ID
Parameters
- ids<Array>
-
Database IDs of models to retrieve
Returns
- Array
-
Collection of Mongoid models
73 74 75 76 77 78 79 80 |
# File 'lib/sunspot/rails/adapters.rb', line 73 def load_all(ids) = if [:select] @clazz.only([:select]).where(:_id.in => ids.map { |id| BSON::ObjectId.from_string(id) }) else @clazz.where(:_id.in => ids.map { |id| BSON::ObjectId.from_string(id) }) end end |