Methods

Class/Module Index [+]

Quicksearch

Mongoid::Reloading

This module handles reloading behaviour of documents.

Public Instance Methods

reload() click to toggle source

Reloads the Document attributes from the database. If the document has not been saved then an error will get raised if the configuration option was set. This can reload root documents or embedded documents.

@example Reload the document.

person.reload

@raise [ Errors::DocumentNotFound ] If the document was deleted.

@return [ Document ] The document, reloaded.

@since 1.0.0

# File lib/mongoid/reloading.rb, line 17
def reload
  _reload.tap do |reloaded|
    if Mongoid.raise_not_found_error && reloaded.empty?
      raise Errors::DocumentNotFound.new(self.class, id)
    end
    @attributes = reloaded
  end
  tap do |doc|
    doc.changed_attributes.clear
    doc.apply_defaults
    doc.reload_relations
    doc.run_callbacks(:initialize)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.