Exception: Mongoid::Errors::DocumentNotFound

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

Overview

Raised when querying the database for a document by a specific id which does not exist. If multiple ids were passed then it will display all of those.

Examples:

Create the error.

DocumentNotFound.new(Person, ["1", "2"])

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(klass, ids) ⇒ DocumentNotFound

Returns a new instance of DocumentNotFound.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mongoid/errors/document_not_found.rb', line 15

def initialize(klass, ids)
  @klass = klass
  @identifiers = ids.is_a?(Array) ? ids.join(", ") : ids

  super(
    translate(
      "document_not_found",
      { :klass => klass.name, :identifiers => identifiers }
    )
  )
end

Instance Attribute Details

#identifiersObject (readonly)

Returns the value of attribute identifiers.



13
14
15
# File 'lib/mongoid/errors/document_not_found.rb', line 13

def identifiers
  @identifiers
end

#klassObject (readonly)

Returns the value of attribute klass.



13
14
15
# File 'lib/mongoid/errors/document_not_found.rb', line 13

def klass
  @klass
end