类:Mongoid::Association::Many
- 继承:
-
Association::Proxy
- 对象
- Association::Proxy
- Mongoid::Association::Many
- 扩展方式:
- 可转发
- 包括:
- 可枚举
- 定义于:
- lib/mongoid/association/many.rb
Overview
这是所有多对一和多对多关联代理的超类。
实例方法摘要折叠
-
#空白? ⇒ true | false
关联是否为空?
-
#cache_version(timestamp_column = :updated_at) ⇒ string
为了与 Rails 的缓存兼容。
-
# create (attributes = nil, type = nil, &block) ⇒ 文档
在引用许多关联上创建新文档。
-
#创建! (attributes = nil, type = nil, &block) ⇒ 文档
在引用许多关联上创建新文档。
-
# find_or_create_by (attrs = {}, type = nil, &block) ⇒ 文档
查找给定条件的第一个文档,或根据提供的条件创建新文档。
-
# find_or_create_by! (attrs = {}, type = nil, &block) ⇒ 文档
查找给定条件的第一个文档,或根据提供的条件创建新文档。
-
# find_or_initialize_by (attrs = {}, type = nil, &block) ⇒ 文档
在给定的条件下查找第一个
Document,或使用所提供的条件实例化一个新文档。 -
# nil? ⇒ false
此代理永远不能为零。
-
# respond_to? (name, include_private = false) ⇒ true | false
由于method_missing被覆盖,我们也应该覆盖它。
-
#作用域"> 条件
这是该协会标准的公开访问权限。
-
#serializable_hash(options = {}) ⇒ Hash
以可序列化哈希的形式获取 document,由 ActiveModel 的JSON和 XML 序列化器使用。
-
# unscoped ⇒ 条件
在未应用默认范围的情况下获取嵌入式文档的条件。
实例方法详细信息
#空白? ⇒ true | false
关联是否为空?
28 29 30 |
# File 'lib/mongoid/association/many.rb', line 28 def 空白? !任何? end |
#cache_version (timestamp_column = :updated_at) ⇒ string
为了与 Rails 的缓存兼容。根据给定时间戳返回一个字符串,并在版本中包含该关系中的记录数。
195 196 197 198 |
# File 'lib/mongoid/association/many.rb', line 195 def cache_version( = :updated_at) @cache_version ||= {} @cache_version[] ||= Compute_cache_version() end |
# create (attributes = nil, type = nil, &block) ⇒文档
在引用许多关联上创建新文档。 如果父文档已持久保存,这将保存文档。
42 43 44 45 46 47 48 49 50 |
# File 'lib/mongoid/association/many.rb', line 42 def 创建(属性 = nil, 类型 = nil, 和块) if 属性.is_a?(::阵列) 属性.map { |attrs| 创建(attrs, 类型, 和块) } else doc = 构建(属性, 类型, 和块) _base.持续存在? ? doc.保存 : Raise_unsaved(doc) doc end end |
#创建! (attributes = nil, type = nil, &block) ⇒文档
在引用许多关联上创建新文档。 如果父文档已持久保存,这将保存文档;如果验证失败,则会引发错误。
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mongoid/association/many.rb', line 65 def 创建!(属性 = nil, 类型 = nil, 和块) if 属性.is_a?(::阵列) 属性.map { |attrs| 创建!(attrs, 类型, 和块) } else doc = 构建(属性, 类型, 和块) 阵列(doc).每 do |doc| doc.try(:run_pending_callbacks) end _base.持续存在? ? doc.save! : Raise_unsaved(doc) doc end end |
# find_or_create_by (attrs = {}, type = nil, &block) ⇒文档
查找给定条件的第一个文档,或根据提供的条件创建新文档。
@param [ Hash ] attrs 要搜索或创建的属性。@param [ Class ] type 要创建的document的可选类型。
90 91 92 |
# File 'lib/mongoid/association/many.rb', line 90 def find_or_create_by(attrs = {}, 类型 = nil, 和块) find_or(:create, attrs, 类型, 和块) end |
# find_or_create_by! (attrs = {}, type = nil, &block) ⇒文档
查找给定条件的第一个文档,或根据提供的条件创建新文档。 如果验证失败,则会引发错误。
106 107 108 |
# File 'lib/mongoid/association/many.rb', line 106 def find_or_create_by!(attrs = {}, 类型 = nil, 和块) find_or(:create!, attrs, 类型, 和块) end |
# find_or_initialize_by (attrs = {}, type = nil, &block) ⇒文档
在给定的条件下查找第一个Document ,或使用所提供的条件实例化一个新文档
120 121 122 |
# File 'lib/mongoid/association/many.rb', line 120 def find_or_initialize_by(attrs = {}, 类型 = nil, 和块) find_or(:build, attrs, 类型, 和块) end |
#nil? ⇒ false
此代理永远不能为零。
130 131 132 |
# File 'lib/mongoid/association/many.rb', line 130 def nil? false end |
# respond_to? (name, include_private = false) ⇒ true | false
由于method_missing被覆盖,我们也应该覆盖它。
143 144 145 146 |
# File 'lib/mongoid/association/many.rb', line 143 def respond_to?(名称, include_private = false) [].respond_to?(名称, include_private) || klass.respond_to?(名称, include_private) || 超 end |
#作用域">条件
这是该协会标准的公开访问权限。
154 155 156 |
# File 'lib/mongoid/association/many.rb', line 154 def 作用域 条件 end |
#serializable_hash(options = {}) ⇒ Hash
以可序列化哈希的形式获取document,由 ActiveModel 的JSON和 XML 序列化器使用。此覆盖只是为了能够传递 :include 和 : except 选项来 get 哈希中的关联。
172 173 174 |
# File 'lib/mongoid/association/many.rb', line 172 def Serializable_hash( = {}) _target.map { |文档| 文档.Serializable_hash() } end |
# unscoped ⇒条件
在未应用默认范围的情况下获取嵌入式文档的条件。
183 184 185 |
# File 'lib/mongoid/association/many.rb', line 183 def 未限定作用域 条件.未限定作用域 end |