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.



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

def _root_document
  self
end

#destroyed?Boolean

Returns:



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

def destroyed?
  @_destroyed == true
end

#new?Boolean

Returns:



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

def new?
  @new
end

#reloadObject



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

def reload
  if doc = self.class.query(:_id => id).query.first
    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