异常:Mongoid::Errors::DocumentNotFound

继承:
MongoidError
  • 对象
显示全部
定义于:
lib/mongoid/errors/document_not_Found.rb

Overview

通过特定 ID 或不存在的属性集在数据库中查询文档时引发此警报。 如果传递了多个 ID,则会显示所有这些 ID。

常量摘要

MongoidError继承的常量

MongoidError::BASE_KEY

实例属性摘要折叠

MongoidError继承的属性

#问题#分辨率#summary

实例方法摘要折叠

MongoidError继承的方法

#compose_message

构造函数详情

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

创建新的错误。

例子:

创建错误。

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

使用属性而不是 ID 创建错误

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

参数:

  • klass ( class )

    模型类。

  • params (哈希 | 数组 | 对象)

    属性或 ID。

  • unmatched 数组 | 哈希 (默认为: nil

    不匹配的 ID(如果适用)。 如果分片键,这将是一个哈希值。



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 初始化(klass, params, unmatched = nil)
  if !unmatched && !params.is_a?(哈希)
    unmatched = 阵列(params) if params
  end

  @klass, @params = klass, params
  (
    compose_message(
      message_key(params, unmatched),
      {
        类: klass.名称,
        搜索: 搜索(params),
        属性: params,
        总数: 总计(params),
        缺失: 缺失(unmatched),
        shard_key: shard_key(unmatched)
      }
    )
  )
end

实例属性详细信息

# klass对象(只读)

返回属性 klass 的值。



12
13
14
# File 'lib/mongoid/errors/document_not_Found.rb', line 12

def klass
  @klass
end

# params对象(只读)

返回属性参数的值。



12
13
14
# File 'lib/mongoid/errors/document_not_Found.rb', line 12

def params
  @params
end