Method: Mongoid::Errors::DocumentNotFound#initialize

Defined in:
lib/mongoid/errors/document_not_found.rb

#initialize(klass, params, unmatched = nil) ⇒ DocumentNotFound

Create the new error.

Examples:

Create the error.

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

Create the error with attributes instead of ids

DocumentNotFound.new(Person, :ssn => "1234", :name => "Helen")


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mongoid/errors/document_not_found.rb', line 26

def initialize(klass, params, unmatched = nil)
  if !unmatched && !params.is_a?(Hash)
    unmatched = Array(params) if params
  end

  @klass, @params = klass, params
  super(
    compose_message(
      message_key(params, unmatched),
      {
        klass: klass.name,
        searched: searched(params),
        attributes: params,
        total: total(params),
        missing: missing(unmatched),
        shard_key: shard_key(unmatched)
      }
    )
  )
end