模块:Mongoid::Association::Referenced::AutoSave
- 扩展方式:
- ActiveSupport::Concern
- 包含在:
- Mongoid::Association
- 定义于:
- lib/mongoid/association/referenced/auto_save.rb
Overview
Mongoid::Document 中包含的 Mixin 模块能力了在保存主题文档时自动将相对侧文档保存在引用关联中的功能。
类方法摘要折叠
-
。 define_autosave! (关联)⇒ 类
在关联对象的关联所属类上定义自动保存方法。
实例方法摘要折叠
-
# __auto Saving__ ⇒ 对象
开始关联的自动保存。
-
#自动保存? ⇒ true | false
用于防止关联的自动保存中出现无限循环。
-
# Changed_for_autosave? (doc) ⇒ 布尔值
检查是否有自动保存的更改。
类方法详细信息
。 define_autosave! (关联)⇒类
在关联对象的关联所属类上定义自动保存方法。
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mongoid/association/referenced/auto_save.rb', line 53 def self.define_autosave!(关联) 关联.inverse_class.点击 do |klass| save_method = :"autosave_documents_for_#{关联.名称}" klass.发送(:define_method, save_method) do if before_callback_halted? self.before_callback_halted = false else __auto Saving__ do if assoc_value = ivar(关联.名称) 阵列(assoc_value).每 do |doc| pc = doc.persistence_context? ? doc.persistence_context : persistence_context.for_child(doc) doc.通过(pc) do |d| d.保存 end end end end end end klass.after_persist_parent save_method, 除非: :autoSaved? end end |
实例方法详细信息
#__autosaving__ ⇒ Object
开始关联的自动保存。
28 29 30 31 32 33 |
# File 'lib/mongoid/association/referenced/auto_save.rb', line 28 def __auto Saving__ 线程化.begin_autosave(self) 产量 确保 线程化.exit_autosave(self) end |
#自动保存? ⇒ true | false
用于防止关联的自动保存中出现无限循环。
20 21 22 |
# File 'lib/mongoid/association/referenced/auto_save.rb', line 20 def 自动保存? 线程化.自动保存?(self) end |
# Changed_for_autosave? (doc) ⇒布尔值
检查是否有自动保存的更改
document.changed_for_autosave?
40 41 42 |
# File 'lib/mongoid/association/referenced/auto_save.rb', line 40 def changed_for_autosave?(doc) doc.new_record? || doc.改变? || doc.marked_for_destruction? end |