- Assigning an object to a belongs_toassociation does not automatically save the object. It does not save the associated object either.
- When you assign an object to a has_oneassociation, that object is automatically saved (in order to update its foreign key).
- In addition, any object being replaced is also automatically saved, because its foreign key will change too
- If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
- If the parent object (the one declaring the has_oneassociation) is unsaved (that is,new_record?returns true) then the child objects are not saved. They will automatically when the parent object is saved.
- If you want to assign an object to a has_one association without saving the object, use the association.buildmethod.
- When you assign an object to a has_manyassociation, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved.
- If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
- If the parent object (the one declaring the has_manyassociation) is unsaved (that is,new_record?returns true) then the child objects are not saved. They will automatically when the parent object is saved.
- If you want to assign an object to a has_manyassociation without saving the object, use theassociation.buildmethod.
- When you assign an object to a has_and_belongs_to_many association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved.
- If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
- If the parent object (the one declaring the has_and_belongs_to_manyassociation) is unsaved (that is,new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved
- If you want to assign an object to a has_and_belongs_to_manyassociation without saving the object, use thecollection.buildmethod
If true, always save the associated object or destroy it if marked for destruction, when saving the parent object. If false, never save or destroy the associated object. By default, only save the associated object if it's a new record.
Note that accepts_nested_attributes_for sets :autosave to true.
@vandamon: When the autosave option isn't present, this feature only works for new records. If you specify autosave: true, also works on updates...