Module: Mongoid::Attributes::Nested::ClassMethods
- Defined in:
- lib/mongoid/attributes/nested.rb
Overview
Constant Summary collapse
- REJECT_ALL_BLANK_PROC =
->(attributes){ attributes.all? { |key, value| key == '_destroy' || value.blank? } }
Instance Method Summary collapse
-
#accepts_nested_attributes_for(*args) ⇒ Object
Used when needing to update related models from a parent relation.
Instance Method Details
#accepts_nested_attributes_for(*args) ⇒ Object
Used when needing to update related models from a parent relation. Can be used on embedded or referenced relations.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongoid/attributes/nested.rb', line 45 def accepts_nested_attributes_for(*args) = args. [:reject_if] = REJECT_ALL_BLANK_PROC if [:reject_if] == :all_blank args.each do |name| meth = "#{name}_attributes=" self.nested_attributes["#{name}_attributes"] = meth = relations[name.to_s] raise Errors::NestedAttributesMetadataNotFound.new(self, name) unless autosave_nested_attributes() re_define_method(meth) do |attrs| _assigning do if .polymorphic? and .inverse_type = .merge!(:class_name => self.send(.inverse_type)) end .nested_builder(attrs, ).build(self) end end end end |