Module: Mongoid::Reloading

Defined in:
lib/custom_fields/extensions/mongoid/document.rb

Overview

This is the base module for all domain objects that need to be persisted to the database as documents.

Instance Method Summary (collapse)

Instance Method Details

- (Document) reload_with_custom_fields

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.

Examples:

Reload the document.

person.reload

Returns:

  • (Document)

    The document, reloaded.

Raises:

  • (Errors::DocumentNotFound)

    If the document was deleted.



46
47
48
49
50
51
52
53
54
# File 'lib/custom_fields/extensions/mongoid/document.rb', line 46

def reload_with_custom_fields
  reload_without_custom_fields.tap do
    instance_variable_names.each do |name|
      if name =~ /_proxy_class$/
        remove_instance_variable("#{name}")
      end
    end
  end
end