method
assign_nested_attributes_for_collection_association
v3.1.0 -
Show latest stable
-
0 notes -
Class: ActiveRecord::NestedAttributes
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8 (0)
- 3.0.0 (-1)
- 3.0.9 (-38)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-23)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
assign_nested_attributes_for_collection_association(association_name, attributes_collection, assignment_opts = {})
private
Assigns the given attributes to the collection association.
Hashes with an :id value matching an existing associated record will update that record. Hashes without an :id value will build a new record for the association. Hashes with a matching :id value and a :_destroy key set to a truthy value will mark the matched record for destruction.
For example:
assign_nested_attributes_for_collection_association(:people, { '1' => { :id => '1', :name => 'Peter' }, '2' => { :name => 'John' }, '3' => { :id => '2', :_destroy => true } })
Will update the name of the Person with ID 1, build a new associated person with the name `John’, and mark the associated Person with ID 2 for destruction.
Also accepts an Array of attribute hashes:
assign_nested_attributes_for_collection_association(:people, [ { :id => '1', :name => 'Peter' }, { :name => 'John' }, { :id => '2', :_destroy => true } ])