异常:Mongoid::Errors::AttributeNotLoaded

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

Overview

尝试读取或写入尚未加载的属性时触发。 使用“.only”或“. without”查询投影方法时,可能会出现这种情况。

例子:

获取尚未加载的字段。

Band.only(:name).first.label
#=> raises Mongoid::Errors::AttributeNotLoaded

设置尚未加载的字段。

Band.without(:label).first.label = 'Sub Pop Records'
#=> raises Mongoid::Errors::AttributeNotLoaded

常量摘要

MongoidError继承的常量

MongoidError::BASE_KEY

实例属性摘要

MongoidError继承的属性

#问题#分辨率#summary

实例方法摘要折叠

MongoidError继承的方法

#compose_message

构造函数详情

#initialize (klass, name) ⇒ AttributeNotLoaded

创建新的错误。

例子:

实例化错误。

AttributeNotLoaded.new(Person, "title")

参数:

  • klass ( class )

    模型类。

  • 名称 ( string | Symbol )

    属性的名称。



27
28
29
30
31
# File 'lib/mongoid/errors/attribute_not_loaded.rb', line 27

def 初始化(klass, 名称)
  (
    compose_message( attribute_not_loaded , { 类: klass.名称, 名称: 名称 })
  )
end