Module: MongoMapper::Plugins::Document::InstanceMethods

Defined in:
lib/mongo_mapper/plugins/document.rb

Instance Method Summary collapse

Instance Method Details

#_root_documentObject

Used by embedded docs to find root easily without if/respond_to? stuff. Documents are always root documents.



35
36
37
# File 'lib/mongo_mapper/plugins/document.rb', line 35

def _root_document
  self
end

#destroyed?Boolean

Returns:



16
17
18
# File 'lib/mongo_mapper/plugins/document.rb', line 16

def destroyed?
  @_destroyed == true
end

#new?Boolean

Returns:



12
13
14
# File 'lib/mongo_mapper/plugins/document.rb', line 12

def new?
  @_new
end

#reloadObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mongo_mapper/plugins/document.rb', line 20

def reload
  if doc = collection.find_one(:_id => id)
    tap do |instance|
      instance.class.associations.each_key do |association_name|
        send(association_name).reset if respond_to?(association_name)
      end
      instance.attributes = doc
    end
  else
    raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
  end
end