Method: MongoModel::DocumentExtensions::Persistence#reload

Defined in:
lib/mongomodel/document/persistence.rb

#reloadObject

Reload the document from the database. If the document hasn’t been saved, this method will raise an error.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mongomodel/document/persistence.rb', line 13

def reload
  reloaded = self.class.unscoped.find(id)

  attributes.clear
  attributes.load!(reloaded.attributes.to_mongo)

  associations.values.each do |association|
    association.proxy.reset
  end

  self
end