Exception: Mongoid::Errors::MixedRelations

Inherits:
MongoidError show all
Defined in:
lib/mongoid/errors/mixed_relations.rb

Overview

This error is raised when trying to reference an embedded document from a document in another collection that is not it’s parent.

Examples:

An illegal reference to an embedded document.

class Post
  include Mongoid::Document
  references_many :addresses
end

class Address
  include Mongoid::Document
  embedded_in :person
  referenced_in :post
end

Since:

  • 2.0.0

Constant Summary

Constants inherited from MongoidError

Mongoid::Errors::MongoidError::BASE_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MongoidError

#translate

Constructor Details

#initialize(root_klass, embedded_klass) ⇒ MixedRelations

Returns a new instance of MixedRelations.

Since:

  • 2.0.0



25
26
27
28
29
30
31
32
33
34
# File 'lib/mongoid/errors/mixed_relations.rb', line 25

def initialize(root_klass, embedded_klass)
  @root_klass, @embedded_klass = root_klass, embedded_klass

  super(
    translate(
      "mixed_relations",
      { :root => root_klass, :embedded => embedded_klass }
    )
  )
end

Instance Attribute Details

#embedded_klassObject (readonly)

Since:

  • 2.0.0



23
24
25
# File 'lib/mongoid/errors/mixed_relations.rb', line 23

def embedded_klass
  @embedded_klass
end

#root_klassObject (readonly)

Since:

  • 2.0.0



23
24
25
# File 'lib/mongoid/errors/mixed_relations.rb', line 23

def root_klass
  @root_klass
end