Class: Sunspot::Mongoid::DataAccessor

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

Instance Method Summary collapse

Instance Method Details

#load(id) ⇒ Object



34
35
36
# File 'lib/sunspot/mongoid.rb', line 34

def load(id)
  @clazz.find(id) rescue nil
end

#load_all(ids) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sunspot/mongoid.rb', line 38

def load_all(ids)
  bson_object_ids = []
  ids.each do |id|
    if BSON::ObjectId.legal?(id)
      bson_object_ids << BSON::ObjectId(id)
    end
  end
  
  # Find object using both id string and BSON::ObjectId initilized from id string
  @clazz.where(:_id.in => bson_object_ids + ids )
end