Exception: MongoModel::DocumentInvalid

Inherits:
DocumentNotSaved show all
Defined in:
lib/mongomodel/support/exceptions.rb

Overview

Raised by save! and create! when the document is invalid. Use the document method to retrieve the document which did not validate.

begin
  complex_operation_that_calls_save!_internally
rescue MongoModel::DocumentInvalid => invalid
  puts invalid.document.errors
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ DocumentInvalid

Returns a new instance of DocumentInvalid.



16
17
18
19
20
21
# File 'lib/mongomodel/support/exceptions.rb', line 16

def initialize(document)
  @document = document

  errors = @document.errors.full_messages.join(I18n.t('support.array.words_connector', :default => ', '))
  super(I18n.t('mongomodel.errors.messages.document_invalid', :errors => errors))
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



14
15
16
# File 'lib/mongomodel/support/exceptions.rb', line 14

def document
  @document
end