Module: Mongoid::Commands::InstanceMethods

Defined in:
lib/mongoid/commands.rb

Instance Method Summary collapse

Instance Method Details

#deleteObject

Delete the Document from the database. Delegates to the Delete command.



38
39
40
# File 'lib/mongoid/commands.rb', line 38

def delete
  Delete.execute(self)
end

#destroyObject

Destroy the Document. Delegates to the Destroy command.



43
44
45
# File 'lib/mongoid/commands.rb', line 43

def destroy
  Destroy.execute(self)
end

#saveObject

Save the Document. Delegates to the Save command.



48
49
50
# File 'lib/mongoid/commands.rb', line 48

def save
  Save.execute(self)
end

#save!Object

Save the Document. Delegates to the Save command. If the command returns false then a ValidationError will be raised.



54
55
56
# File 'lib/mongoid/commands.rb', line 54

def save!
  Save.execute(self) || (raise ValidationsError)
end

#update_attributes(attributes = {}) ⇒ Object

Update the attributes of the Document. Will call save after the attributes have been updated.



60
61
62
# File 'lib/mongoid/commands.rb', line 60

def update_attributes(attributes = {})
  self.attributes = attributes; save
end

#update_attributes!(attribtues = {}) ⇒ Object

Update the attributes of the Document. Will call save! after the attributes have been updated, causing a ValidationError if the Document failed validation.



67
68
69
# File 'lib/mongoid/commands.rb', line 67

def update_attributes!(attribtues = {})
  self.attributes = attributes; save!
end