模块:Mongoid::Persistable
- 扩展方式:
- ActiveSupport::Concern
- 包括:
- Creatable 、 Deletable 、 Destroyable 、 Incrementable 、 Logical 、 Maxable 、 Minable 、 Multipliable 、 Poppable 、 Pullable 、 Pushable 、 Renameable 、 Saveable 、 Settable 、 Unsettable 、 Updatable 、 Upsertable 、 Positional
- 包含在:
- 可组合
- 定义于:
- lib/mongoid/persistable.rb ,
lib/mongoid/persistable/logic.rb,
lib/mongoid/persistable/maxable.rb,
lib/mongoid/persistable/minable.rb,
lib/mongoid/persistable/savable.rb,
lib/mongoid/persistable/poppable.rb,
lib/mongoid/persistable/pullable.rb,
lib/mongoid/persistable/pushable.rb,
lib/mongoid/persistable/settable.rb,
lib/mongoid/persistable/creatable.rb,
lib/mongoid/persistable/deletable.rb,
lib/mongoid/persistable/renameable.rb,
lib/mongoid/persistable/updatable.rb,
lib/mongoid/persistable/unsettable.rb,
lib/mongoid/persistable/upsertable.rb,
lib/mongoid/persistable/destroyable.rb,
lib/mongoid/persistable/multipliable.rb,
lib/mongoid/persistable/incrementable.rb
Overview
包含持久性操作的一般行为。
在命名空间下定义
模块: Creatable 、 Deletable 、 Destroyable 、 Incrementable 、 Logical 、 Maxable 、 Minable 、 Multipliable 、 Poppable 、 Pullable 、 Pushable 、 Renameable 、 Saveable 、 Settable 、 Unsettable 、 Updateable 、 Upsertable
常量摘要折叠
- LIST_OPERATIONS =
处理数据库中数组或集的原子操作。
[ "$addToSet", " $push ", " $pull ", " $pullAll " ].冻结
实例方法摘要折叠
-
#自动(join_context: nil) ⇒ true | false
对区块内可能发生的所有事情以原子方式(在单个数据库调用中)执行操作。
-
# fail_due_to_callback! (方法)→ 对象
如果回调失败,则引发错误。
-
# fail_due_to_validation! ⇒ 对象
如果验证失败,则引发错误。
Unsettable 中包含的方法
Upsertable 中包含的方法
Updateable中包含的方法
#update, #update!, #update_attribute
Settable中包含的方法
Saveable中包含的方法
Renameable 中包含的方法
Pushable 中包含的方法
Pullable 中包含的方法
位置包含的方法
Poppable 中包含的方法
Multipliable中包含的方法
Minable 中包含的方法
Maxable中包含的方法
包含在以下方法中的方法:
Incrementable中包含的方法
Destroyable中包含的方法
从Deletable包含的方法
Createtable中包含的方法
实例方法详细信息
#自动(join_context: nil) ⇒ true | false
对区块内可能发生的所有事情以原子方式(在单个数据库调用中)执行操作。 此方法支持以原子方式嵌套进一步调用,这将根据下述选项运行。
可以指定 join_context 选项,为 true 时,将把给定块声明的操作与包装同一文档的当前调用的原子块(如果存在)合并。 如果此区块或共享相同上下文的任何其他区块在持久化之前引发,则该上下文的所有操作都将不会被持久化,并且也将在内存中重置。
当 join_context 为 false 时,给定的操作块将独立于其他上下文而持久保存。 只要此区块能够运行并持久化更改,其他上下文中的故障就不会影响此上下文。
join_context 的默认值由全局配置选项 join_contexts设立,该选项自身的默认值为 false。
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/mongoid/persistable.rb', line 94 def 原子地(join_context: nil) join_context = Mongoid.join_contexts if join_context.nil? call_depth = @atomic_depth ||= 0 has_own_context = call_depth.zero? || !join_context @atomic_updates_to_execute_stack ||= [] _mongoid_push_atomic_context if has_own_context if block_given? @atomic_depth += 1 产量(self) @atomic_depth -= 1 end if has_own_context persist_atomic_operations @atomic_context _mongoid_remove_atomic_context_changes end true 救援 StandardError => e _mongoid_reset_atomic_context_changes! if has_own_context 提高 e 确保 _mongoid_pop_atomic_context if has_own_context if call_depth.zero? @atomic_depth = nil @atomic_updates_to_execute_stack = nil end end |