Exception: Mongoid::Errors::AmbiguousRelationship

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

Overview

This error is raised in case of an ambiguous association.

Examples:

An ambiguous association.

class Person
  include Mongoid::Document

  has_many :invitations, inverse_of: :person
  has_many :referred_invitations, class_name: "Invitation", inverse_of: :referred_by
end

class Invitation
  include Mongoid::Document

  belongs_to :person
  belongs_to :referred_by, class_name: "Person"
end

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, inverse, name, candidates) ⇒ AmbiguousRelationship

Create the new error.

Examples:

Create the error.

AmbiguousRelationship.new(
  Person, Drug, :person, [ :drugs, :evil_drugs ]
)

Parameters:

  • klass (Class)

    The base class.

  • inverse (Class)

    The inverse class.

  • name (Symbol)

    The relation name.

  • candidates (Array<Symbol>)

    The potential inverses.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mongoid/errors/ambiguous_relationship.rb', line 36

def initialize(klass, inverse, name, candidates)
  super(
    compose_message(
      "ambiguous_relationship",
      {
        klass: klass,
        inverse: inverse,
        name: name.inspect,
        candidates: candidates.map(&:inspect).join(", ")
      }
    )
  )
end