Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dreamingblackcat/1a8c48b9a8107db0759aa1bf85259263 to your computer and use it in GitHub Desktop.

Select an option

Save dreamingblackcat/1a8c48b9a8107db0759aa1bf85259263 to your computer and use it in GitHub Desktop.

Revisions

  1. @demisx demisx revised this gist Jun 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    1. When you assign an object to a `has_many` association, 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.
    2. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    3. If the parent object (the one declaring the `has_many` association) is unsaved (that is, `new_record?` returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    4. If you want to assign an object to a has_many association without saving the object, use the `association.build` method.
    4. If you want to assign an object to a `has_many` association without saving the object, use the `association.build` method.


    #### has_and_belongs_to_many:
  2. @demisx demisx revised this gist Jun 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    1. When you assign an object to a `has_many` association, 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.
    2. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    3. If the parent object (the one declaring the `has_many` association) is unsaved (that is, `new_record?` returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    4. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.
    4. If you want to assign an object to a has_many association without saving the object, use the `association.build` method.


    #### has_and_belongs_to_many:
  3. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,6 @@


    #### has_and_belongs_to_many:
    ------------------------
    1. 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.
    2. If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment
  4. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -27,4 +27,11 @@
    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
    4. If you want to assign an object to a `has_and_belongs_to_many` association without saving the object,
    use the `collection.build` method
    use the `collection.build` method

    :autosave
    ----------

    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.
  5. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,17 @@
    1. When you assign an object to a `has_many` association, 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.
    2. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    3. If the parent object (the one declaring the `has_many` association) is unsaved (that is, `new_record?` returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    4. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.
    4. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.


    #### has_and_belongs_to_many:
    ------------------------
    1. 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.
    2. If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment
    itself is cancelled.
    3. If the parent object (the one declaring the `has_and_belongs_to_many` association) 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
    4. If you want to assign an object to a `has_and_belongs_to_many` association without saving the object,
    use the `collection.build` method
  6. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    #### belongs_to:

    1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.
    1. Assigning an object to a `belongs_to` association does not automatically save the object. It does not save the associated object either.

    #### has_one:

    1. When you assign an object to a `has_one` association, that object is automatically saved (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
    3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, `new_record?` returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    5. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.

    #### has_many:
    1. When you assign an object to a has_many association, 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.
    1. When you assign an object to a `has_many` association, 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.
    2. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    3. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    3. If the parent object (the one declaring the `has_many` association) is unsaved (that is, `new_record?` returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    4. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.
  7. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@

    #### has_one:

    1. When you assign an object to a _has_one_ association, that object is automatically saved (in order to update its foreign key).
    1. When you assign an object to a `has_one` association, that object is automatically saved (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
    3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
  8. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion active_record_objects_autosave.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@

    #### has_one:

    1. When you assign an object to a *has_one* association, that object is automatically saved (in order to update its foreign key).
    1. When you assign an object to a _has_one_ association, that object is automatically saved (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
    3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
  9. @demisx demisx renamed this gist Mar 31, 2014. 1 changed file with 0 additions and 0 deletions.
  10. @demisx demisx revised this gist Mar 31, 2014. 2 changed files with 17 additions and 12 deletions.
    17 changes: 17 additions & 0 deletions active_record_objects_autosave
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #### belongs_to:

    1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

    #### has_one:

    1. When you assign an object to a *has_one* association, that object is automatically saved (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
    3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    5. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.

    #### has_many:
    1. When you assign an object to a has_many association, 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.
    2. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    3. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    4. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.
    12 changes: 0 additions & 12 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +0,0 @@
    #### belongs_to:

    1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

    #### has_one:

    1. When you assign an object to a has_one association, that object is automatically saved
    (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
    3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    5. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.
  11. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    *belongs_to:*
    #### belongs_to:

    1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

    *has_one:*
    #### has_one:

    1. When you assign an object to a has_one association, that object is automatically saved
    (in order to update its foreign key).
  12. @demisx demisx revised this gist Mar 31, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    *belongs_to:*

    1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

    *has_one:*

    1. When you assign an object to a has_one association, that object is automatically saved
    (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  13. @demisx demisx created this gist Mar 31, 2014.
    10 changes: 10 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    *belongs_to:*
    1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

    *has_one:*
    1. When you assign an object to a has_one association, that object is automatically saved
    (in order to update its foreign key).
    2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
    3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
    4. If the parent object (the one declaring the `has_one` association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
    5. If you want to assign an object to a has_one association without saving the object, use the `association.build` method.