模块:Mongoid::Association::Depending

扩展方式:
ActiveSupport::Concern
包含在:
Mongoid::Association
定义于:
lib/mongoid/association/depending.rb

Overview

该模块定义了为关联设置级联删除和无效的行为,以及如何委托给适当的策略。

常量摘要折叠

STRATEGIES =

有效的依赖策略。

[
    :delete_all,
    :destroy,
    :nullify,
    :restrict_with_Exception,
    :restrict_with_error
]

类方法摘要折叠

实例方法摘要折叠

类方法详细信息

define_dependency! (关联)⇒

尝试为文档添加级联信息,以了解如何在删除时处理关联文档。

例子:

设置级联信息

Mongoid::Association::Depending.define_dependency!(association)

参数:

返回:

  • ( class )

    文档的类。



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mongoid/association/depending.rb', line 57

def self.define_dependency!(关联)
  validate!(关联)
  关联.inverse_class.点击 do |klass|
    if klass.Depends_Owner != klass
      klass.受抚养人 = []
      klass.Depends_Owner = klass
    end

    if 关联.依赖 && !klass.受抚养人.包括?(关联)
      klass.受抚养人.推动(关联)
    end
  end
end

validate! (关联)→对象

验证关联的依赖策略是否在允许的枚举范围内。

参数:



79
80
81
82
83
84
85
# File 'lib/mongoid/association/depending.rb', line 79

def self.validate!(关联)
  除非 策略.包括?(关联.依赖)
    提高 Errors::InvalidDependentStrategy.new(关联,
                                               关联.依赖,
                                               策略)
  end
end

实例方法详细信息

# apply_destroy_dependencies!对象

执行所有级联删除、销毁或作空操作。 将委托给适当的策略来执行操作。

例子:

执行级联。

document.apply_destroy_dependencies!


92
93
94
95
96
97
98
# File 'lib/mongoid/association/depending.rb', line 92

def apply_destroy_dependencies!
  self.class._all_depends. do |关联|
    if 依赖 = 关联.try(:depend)
      发送(" _depend_ #{ Independent } ! ", 关联)
    end
  end
end