异常:Mongoid::Errors::InvalidSetPolymorphicRelation

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

Overview

尝试设立与 model 的多态“引用”关联,其中多个“引用多/一”关联指向第一个 model 时,则引发此警报。

例子:

多态关联设置无效。

class Face
  include Mongoid::Document

  has_one :left_eye, class_name: "Eye", as: :eyeable
  has_one :right_eye, class_name: "Eye", as: :eyeable
end

class Eye
  include Mongoid::Document

  belongs_to :eyeable, polymorphic: true
end

eye = Eye.new
face = Face.new
eye.eyeable = face # Raises error

常量摘要

从MongoidError继承的常量

MongoidError::BASE_KEY

实例属性摘要

从MongoidError继承的属性

#问题、 #分辨率、 #summary

实例方法摘要折叠

从MongoidError继承的方法

#compose_message

构造函数详情

#initialize (name, klass, other_klass) ⇒ InvalidSetPolymorphicRelation

创建新的无效设立多态关联错误。

例子:

创建错误。

InvalidSetPolymorphicRelation.new


31
32
33
34
# File 'lib/mongoid/errors/invalid_set_polymorphic_relation.rb', line 31

def 初始化(名称, klass, other_klass)
  超(compose_message('invalid_set_poly态_relation',
                        { 名称: 名称, 类: klass, other_klass: other_klass }))
end