Exception: Mongoid::Errors::ImmutableAttribute

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

Overview

This error is raised when attempting the change the value of an immutable attribute. For example, the _id attribute is immutable, and attempting to change it on a document that has already been persisted will result in this error.

Constant Summary

Constants inherited from MongoidError

MongoidError::BASE_KEY

Instance Attribute Summary

Attributes inherited from MongoidError

#problem, #resolution, #summary

Instance Method Summary collapse

Methods inherited from MongoidError

#compose_message

Constructor Details

#initialize(name, value) ⇒ ImmutableAttribute

Create the new error.

Examples:

Create the new error.

ImmutableAttribute.new(:_id, "1234")

Parameters:

  • name (Symbol | String)

    The name of the attribute.

  • value (Object)

    The attempted set value.



20
21
22
23
24
# File 'lib/mongoid/errors/immutable_attribute.rb', line 20

def initialize(name, value)
  super(
    compose_message("immutable_attribute", { name: name, value: value })
  )
end