예외: Mongoid::Errors::UnrecognizedModelAlias

상속:
MongoidError
  • 객체
모두 표시
다음에 정의됨:
lib/mongoid/errors/unrecognized_model_alias.rb

개요

다형성 연관이 쿼리되지만 연관 유형을 확인할 수 없을 때 발생합니다. 이는 일반적으로 데이터베이스 의 데이터가 더 이상 존재하지 않는 유형을 참조할 때 발생합니다.

예시 들어 다음 모델을 가정해 보겠습니다.

class Manager
include Mongoid::Document
belongs_to :unit, polymorphic: true
end

Imagine there is a document in the managers collection that looks something like this:

{ _id: ..., unit_id: ..., unit_type: 'Department::Engineering' }

If, at some point in your refactoring, you rename the Department::Engineering model to something else, Mongoid will no longer be able to resolve the type of this association, and asking for manager.unit will raise this exception.

이 예외를 수정하려면 모델 클래스에 별칭을 추가하여 이름을 바꾼 후에도 해당 모델을 찾을 수 있도록 할 수 있습니다.

module Engineering
class Department
  include Mongoid::Document

  identify_as 'Department::Engineering'

  # ...
end
end

Better practice would be to use unique strings instead of class names to identify these polymorphic types in the database (e.g. 'dept' instead of 'Department::Engineering').

상수 요약

MongoidError에서 상속된 상수

MongoidError::BASE_KEY

인스턴스 속성 요약

MongoidError에서 상속된 속성

#problem, #Resolution, #summary

인스턴스 메서드 요약 접기

MongoidError에서 상속된 메서드

#compose_message

생성자 세부 정보

#initialize(model_alias) ⇒ UnrecognizedModelAlias

UnrecognizedModelAlias의 새 인스턴스 반환합니다.



43
44
45
46
47
48
49
50
# 파일 'lib/mongoid/errors/unrecognized_model_alias.rb', 줄 43

def 초기화(model_alias)
  super(
    Compose_message(
      'unrecognized_model_alias ',
      model_alias: model_alias.검사
    )
  )
end