Exception: Mongoid::Errors::InvalidSetPolymorphicRelation

Inherits:
MongoidError
  • Object
show all
Defined in:
lib/mongoid/errors/invalid_set_polymorphic_relation.rb

Overview

Raised when trying to set a polymorphic “references in” relation to a model with multiple “references many/one” relations pointing to that first model.

Examples:

Invalid setting of a polymorphic relation.

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

Constant Summary

Constants inherited from MongoidError

MongoidError::BASE_KEY

Instance Method Summary collapse

Methods inherited from MongoidError

#compose_message

Constructor Details

#initialize(name, klass, other_klass) ⇒ InvalidSetPolymorphicRelation

Create the new invalid set polymorphic relation error.

Examples:

Create the error.

InvalidSetPolymorphicRelation.new


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

def initialize(name, klass, other_klass)
  super(compose_message("invalid_set_polymorphic_relation", { name: name, klass: klass, other_klass: other_klass }))
end