123456789_123456789_123456789_123456789_123456789_

Exception: Mongoid::Errors::InvalidSetPolymorphicRelation

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, MongoidError, StandardError
Instance Chain:
self, MongoidError, StandardError
Inherits: Mongoid::Errors::MongoidError
Defined in: lib/mongoid/errors/invalid_set_polymorphic_relation.rb

Overview

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

Examples:

Invalid setting of a polymorphic association.

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

MongoidError - Inherited

BASE_KEY

Class Method Summary

Instance Attribute Summary

Instance Method Summary

MongoidError - Inherited

#compose_message

Compose the message.

#translate

Given the key of the specific error and the options hash, translate the message.

#translate_problem

Create the problem.

#translate_resolution

Create the resolution.

#translate_summary

Create the summary.

Constructor Details

.new(name, klass, other_klass) ⇒ InvalidSetPolymorphicRelation

Create the new invalid set polymorphic association error.

Examples:

Create the error.

InvalidSetPolymorphicRelation.new
[ GitHub ]

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

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