모듈: Mongoid::Persistable::Renameable

확장자:
ActiveSupport::Concern
포함 항목:
Mongoid::Persistable
다음에 정의됨:
lib/mongoid/persistable/renameable.rb

개요

$rename 작업에 대한 동작을 정의합니다.

인스턴스 메서드 요약 접기

인스턴스 메서드 세부 정보

#rename(renames) ⇒ 문서

참고:

많은 연관 관계가 포함된 필드에는 이 기능이 적용되지 않습니다.

$rename을(를) 통해 필드 이름을 한 값에서 다른 값으로 바꿉니다.

예시:

필드 이름을 변경합니다.

document.rename(title: "salutation", name: "nombre")

매개변수:

  • rename (해시)

    이전 이름/새 이름 쌍의 이름을 바꿉니다.

반환합니다:

  • (문서)

    문서입니다.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 파일 'lib/mongoid/persistable/renameable.rb', 줄 21

def 이름 변경(rename)
  prepare_atomic_operation do |ops|
    process_atomic_operations(rename) do |old_field, new_field|
      new_name = new_field.to_s
      만약 execution_atomally?
        process_attribute new_name, 속성[old_field]
        process_attribute old_field, nil
      other
        속성[new_name] = 속성.삭제(old_field)
      end
      ops[atomic_attribute_name(old_field)] = atomic_attribute_name(new_name)
    end
    { "$rename" => ops }
  end
end