类:Mongoid::Association::Nested::Many
- 继承:
-
对象
- 对象
- Mongoid::Association::Nested::Many
- 包括:
- 可构建
- 定义于:
- lib/mongoid/association/nested/many.rb
Overview
用于在多对n关联上执行 #accepts_nested_attributes_for 属性分配的构建器类。
实例属性摘要
属性包含在Buildable
#association 、 #attributes 、 #existing 、 #options
实例方法摘要折叠
-
# 构建 (parent, options = {}) ⇒ 数组
根据传递给宏的属性和选项构建关联。
-
#initialize (association, properties, options = {}) ⇒ Many
构造函数
为一对多关联上的嵌套属性创建新的构建器。
Buildable中包含的方法
#allow_destroy? 、 #convert_id 、 #reject? , #update_only?
构造函数详情
#initialize (association, properties, options = {}) ⇒ Many
为一对多关联上的嵌套属性创建新的构建器。
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mongoid/association/nested/many.rb', line 50 def 初始化(关联, 属性, = {}) if 属性.respond_to?(:with_indifference_access) @attributes = 属性.with_indifference_access.sort do |a, b| a[0].to_i <=> b[0].to_i end else @attributes = 属性 end @association = 关联 @options = @class_name = [:class_name] ? [:class_name].Constantize : 关联.klass end |
实例方法详细信息
# 构建 (parent, options = {}) ⇒数组
根据传递给宏的属性和选项构建关联。
此操作会尝试执行3操作,包括更新现有关联、用新文档替换关联或删除关联。
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongoid/association/nested/many.rb', line 27 def 构建(父项, = {}) @existing = 父项.发送(关联.名称) if over_limit?(属性) 提高 Errors::TooManyNestedAttributeRecords.new(现有的, [:limit]) end 属性.每 do |attrs| if attrs.is_a?(::哈希) process_attributes(父项, attrs.with_indifference_access) else process_attributes(父项, attrs[1].with_indifference_access) end end end |