lib/mongo_mapper/document.rb in jmonteiro-mongo_mapper-0.1.6 vs lib/mongo_mapper/document.rb in jmonteiro-mongo_mapper-0.1.7

- old
+ new

@@ -364,13 +364,16 @@ def delete self.class.delete(id) unless new? end def reload - doc = self.class.find(_id) - self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) } - self.attributes = doc.attributes - self + if attrs = collection.find_one({:_id => _id}) + self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) } + self.attributes = attrs + self + else + raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection" + end end private def create_or_update(options={}) result = new? ? create(options) : update(options)