Exception: Mongoid::Errors::UnsavedDocument

Inherits:
MongoidError show all
Defined in:
lib/mongoid/errors/unsaved_document.rb

Overview

Raised when attempting to call create or create! through a references_many when the parent document has not been saved. This prevents the child from getting presisted and immediately being orphaned.

Constant Summary

Constants inherited from MongoidError

MongoidError::BASE_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MongoidError

#translate

Constructor Details

#initialize(base, document) ⇒ UnsavedDocument

Returns a new instance of UnsavedDocument.



12
13
14
15
16
17
18
19
20
# File 'lib/mongoid/errors/unsaved_document.rb', line 12

def initialize(base, document)
  @base, @document = base, document
  super(
    translate(
      "unsaved_document",
      { :base => base.class.name, :document => document.class.name }
    )
  )
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



10
11
12
# File 'lib/mongoid/errors/unsaved_document.rb', line 10

def base
  @base
end

#documentObject (readonly)

Returns the value of attribute document.



10
11
12
# File 'lib/mongoid/errors/unsaved_document.rb', line 10

def document
  @document
end