类:Mongoid::Association::Many
Overview
这是所有多对一和多对多关联代理的超类。
常量摘要
从Proxy继承的常量
实例属性摘要
从Proxy继承的属性
#_association 、 #_base 、 #_target
实例方法摘要折叠
-
#空白? ⇒ true | false
关联是否为空?
-
# 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
以可序列化哈希的形式获取文档,由 ActiveModel 的JSON和 XML 序列化器使用。
-
# unscoped ⇒ 条件
在未应用默认范围的情况下获取嵌入式文档的条件。
从Proxy继承的方法
apply_ordering 、 #extend_proxies 、 #initialize 、 #klass 、 #reset_unloaded 、 #substitutable
包含在封送处理中的方法
构造函数详情
该类从Mongoid::Association::Proxy继承了一个构造函数
实例方法详细信息
#空白? ⇒ true | false
关联是否为空?
22 23 24 |
# File 'lib/mongoid/association/many.rb', line 22 def 空白? !任何? end |
# create (attributes = nil, type = nil, &block) ⇒文档
在引用许多关联上创建新文档。 如果父文档已持久保存,这将保存文档。
36 37 38 39 40 41 42 43 44 |
# File 'lib/mongoid/association/many.rb', line 36 def 创建(属性 = nil, 类型 = nil, 和块) if 属性.is_a?(::阵列) 属性.map { |attrs| 创建(attrs, 类型, 和块) } else doc = 构建(属性, 类型, 和块) _base.持续存在? ? doc.保存 : Raise_unsaved(doc) doc end end |
#创建! (attributes = nil, type = nil, &block) ⇒文档
在引用许多关联上创建新文档。 如果父文档已持久保存,这将保存文档;如果验证失败,则会引发错误。
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mongoid/association/many.rb', line 59 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 The attributes to search or create with.
@param [ Class ] type The optional type of document to create.
84 85 86 |
# File 'lib/mongoid/association/many.rb', line 84 def find_or_create_by(attrs = {}, 类型 = nil, 和块) find_or(:create, attrs, 类型, 和块) end |
# find_or_create_by! (attrs = {}, type = nil, &block) ⇒文档
查找给定条件的第一个文档,或根据提供的条件创建新文档。 如果验证失败,则会引发错误。
100 101 102 |
# File 'lib/mongoid/association/many.rb', line 100 def find_or_create_by!(attrs = {}, 类型 = nil, 和块) find_or(:create!, attrs, 类型, 和块) end |
# find_or_initialize_by (attrs = {}, type = nil, &block) ⇒文档
在给定的条件下查找第一个Document ,或使用所提供的条件实例化一个新文档
114 115 116 |
# File 'lib/mongoid/association/many.rb', line 114 def find_or_initialize_by(attrs = {}, 类型 = nil, 和块) find_or(:build, attrs, 类型, 和块) end |
#nil? ⇒ false
此代理永远不能为零。
124 125 126 |
# File 'lib/mongoid/association/many.rb', line 124 def nil? false end |
# respond_to? (name, include_private = false) ⇒ true | false
由于method_missing被覆盖,我们也应该覆盖它。
137 138 139 140 |
# File 'lib/mongoid/association/many.rb', line 137 def respond_to?(名称, include_private = false) [].respond_to?(名称, include_private) || klass.respond_to?(名称, include_private) || 超 end |
#作用域">条件
这是该协会标准的公开访问权限。
148 149 150 |
# File 'lib/mongoid/association/many.rb', line 148 def 作用域 条件 end |
#serializable_hash(options = {}) ⇒ Hash
以可序列化哈希的形式获取文档,由 ActiveModel 的JSON和 XML 序列化器使用。 此覆盖只是为了能够传递 :include 和 : except 选项来获取哈希中的关联。
166 167 168 |
# File 'lib/mongoid/association/many.rb', line 166 def Serializable_hash( = {}) _target.map { |文档| 文档.Serializable_hash() } end |
# unscoped ⇒条件
在未应用默认范围的情况下获取嵌入式文档的条件。
177 178 179 |
# File 'lib/mongoid/association/many.rb', line 177 def 未限定作用域 条件.未限定作用域 end |