模块:Mongoid::Attributes::Nested::ClassMethods
- 定义于:
- lib/mongoid/attributes/nested.rb
常量摘要折叠
- REJECT_ALL_BLANK_PROC =
->(属性){ 属性.全部? { |key, 值| key == ' _destroy ' || 值.空白? } }
实例方法摘要折叠
-
#accepts_nested_attributes_for (*args) ⇒ 对象
当需要从父关联更新相关模型时使用。
实例方法详细信息
#accepts_nested_attributes_for (*args) ⇒对象
当需要从父关联更新相关模型时使用。 可用于嵌入式或引用关联。
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mongoid/attributes/nested.rb', line 48 def accept_nested_attributes_for(*args) = args..dup [:autosave] = true if [:autosave].nil? [:reject_if] = REJECT_ALL_BLANK_PROC if [:reject_if] == :all_blank args.每 do |名称| meth = " #{ name } _attributes= " self.nested_attributes[" #{ name } _attributes "] = meth 关联 = 关系[名称.to_s] 提高 Errors::NestedAttributesMetadataNotFound.new(self, 名称) 除非 关联 autosave_nested_attributes(关联) if [:autosave] re_define_method(meth) do |attrs| _assing do if 关联.多态? 和 关联.inverse_type klass = 关联.解析器.model_for(发送(关联.inverse_type)) = .合并!(:class_name => klass) end 关联.nested_builder(attrs, ).构建(self) end end end end |