Exception: Mongoid::Errors::AttributeNotLoaded

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

Overview

Raised when attempting to read or write an attribute which has not been loaded. This can occur when using ‘.only` or `.without` query projection methods.

Examples:

Getting a field which has not been loaded.

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

Setting a field which has not been loaded.

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

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(klass, name) ⇒ AttributeNotLoaded

Create the new error.

Examples:

Instantiate the error.

AttributeNotLoaded.new(Person, "title")

Parameters:

  • klass (Class)

    The model class.

  • name (String | Symbol)

    The name of the attribute.



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

def initialize(klass, name)
  super(
    compose_message("attribute_not_loaded", { klass: klass.name, name: name })
  )
end