Method: Mongoid::Relations::Builders::NestedAttributes::Many#build
- Defined in:
- lib/mongoid/relations/builders/nested_attributes/many.rb
#build(parent) ⇒ Array
Builds the relation depending on the attributes and the options passed to the macro.
This attempts to perform 3 operations, either one of an update of the existing relation, a replacement of the relation with a new document, or a removal of the relation.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/relations/builders/nested_attributes/many.rb', line 21 def build(parent) @existing = parent.send(.name) if over_limit?(attributes) raise Errors::TooManyNestedAttributeRecords.new(existing, [:limit]) end attributes.each do |attrs| if attrs.respond_to?(:with_indifferent_access) process(parent, attrs) else process(parent, attrs[1]) end end end |