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