모듈: Mongoid::Association::Builders

확장자:
ActiveSupport::Concern
포함 항목:
Mongoid::Association
다음에 정의됨:
lib/mongoid/association/ 빌더.rb

개요

이 모듈은 일대일 연관 관계에 사용되는 빌드 및 생성 메서드를 정의하는 역할을 합니다.

예시:

생성되는 메서드.


class Person
  include Mongoid::Document
  embeds_one :name
end

# The following methods get created:
person.build_name({ :first_name => "Durran" })
person.create_name({ :first_name => "Durran" })

클래스 메서드 요약 접기

클래스 메서드 세부 정보

.describe_builder!(association) ⇒ 클래스

빌더 메서드를 정의합니다. 이는 #build_name으로 정의됩니다.

예시:

Person.define_builder!(association)

매개변수:

반환합니다:

  • (클래스)

    클래스를 설정하다 중입니다.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 파일 'lib/mongoid/association/ 빌더.rb', 줄 47

def self.describe_builder!(연관 관계)
  연관 관계.inverse_class. do |class|
    class.re_define_method("build_#{association.name }") do |*args|
      속성, 유형, _opts = parse_args(args)

      문서 = 공장.execution_build(유형 || 연관 관계.관계 클래스, 속성, execution_callbacks: 거짓)
      _build do
        자식 = send("#{연관 관계.이름}=", 문서)
        자식.run_pending_callbacks
        자식.run_callbacks(:build)
        자식
      end
    end
  end
end

.describe_creator!(association) ⇒ 클래스

작성자 메서드를 정의합니다. 이는 #create_name으로 정의됩니다. 객체 가 빌드되면 즉시 저장됩니다.

예시:

Person.define_creator!(association)

매개변수:

반환합니다:

  • (클래스)

    클래스를 설정하다 중입니다.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 파일 'lib/mongoid/association/ 빌더.rb', 줄 72

def self.describe_creator!(연관 관계)
  연관 관계.inverse_class. do |class|
    class.re_define_method("create_#{association.name}") do |*args|
      속성, 유형, _opts = parse_args(args)

      문서 = 공장.execution_build(유형 || 연관 관계.관계 클래스, 속성, execution_callbacks: 거짓)
      doc = _assigning do
        send("#{연관 관계.이름}=", 문서)
      end
      doc.run_pending_callbacks
      doc.저장
      저장 만약 new_record? && 연관 관계.Stores_foreign_key?
      doc
    end
  end
end