模块:Mongoid::Clients::Options
- 扩展方式:
- ActiveSupport::Concern
- 定义于:
- lib/mongoid/clients/options.rb
Overview
Mongoid::Document 中包含的 Mixin 模块能力了管理数据库上下文以实现持久性和查询操作的能力。 示例,这包括将文档保存到不同的集合,以及从从从节点(secondary node from replica set)实例读取文档。
在命名空间下定义
模块: 类方法
实例方法摘要折叠
-
# 集合 (parent = nil) ⇒ Mongo::Collection
获取document的当前持久性上下文的集合。
-
# collection_name ⇒ string
获取document的当前持久性上下文的集合名称。
-
# mongo_client ⇒ Mongo::Client
获取 document 的当前持久性上下文的数据库客户端。
-
#persistence_context ⇒ Mongoid::PersistenceContext
获取 document 的当前持久性上下文。
-
#persistence_context? ⇒ true | false
返回是否为 document 或 document 的类设立了持久性上下文。
-
#with(options_or_context) ⇒ 对象
在区块期间更改此对象的持久性上下文。
实例方法详细信息
# 集合 (parent = nil) ⇒ Mongo::Collection
获取document的当前持久性上下文的集合。
45 46 47 |
# File 'lib/mongoid/clients/options.rb', line 45 def 集合(父项 = nil) persistence_context.集合(父项) end |
# collection_name ⇒ string
获取document的当前持久性上下文的集合名称。
56 57 58 |
# File 'lib/mongoid/clients/options.rb', line 56 def collection_name persistence_context.collection_name end |
# mongo_client ⇒ Mongo::Client
获取 document 的当前持久性上下文的数据库客户端。
67 68 69 |
# File 'lib/mongoid/clients/options.rb', line 67 def mongo_client persistence_context.客户端 end |
#persistence_context ⇒ Mongoid::PersistenceContext
注意:
对于嵌入式文档,返回根父文档的持久性上下文。
获取 document 的当前持久性上下文。
81 82 83 84 85 86 87 88 89 |
# File 'lib/mongoid/clients/options.rb', line 81 def persistence_context if && !_root? _root.persistence_context else PersistenceContext.获取(self) || PersistenceContext.获取(self.class) || PersistenceContext.new(self.class, ) end end |
#persistence_context? ⇒ true | false
注意:
对于嵌入式文档,使用根父文档的持久性上下文。
返回是否为 document 或 document 的类设立了持久性上下文。
101 102 103 104 105 106 107 108 109 |
# File 'lib/mongoid/clients/options.rb', line 101 def persistence_context? if && !_root? _root.persistence_context? else &。任何? || PersistenceContext.获取(self).现在? || PersistenceContext.获取(self.class).现在? end end |
#with (options_or_context) ⇒ 对象
在区块期间更改此对象的持久性上下文。
26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/clients/options.rb', line 26 def 通过() ORIGIN_CONTEXT = PersistenceContext.获取(self) original_cluster = persistence_context.集群 set_persistence_context() 产量 self 确保 clear_persistence_context(original_cluster, ORIGIN_CONTEXT) end |