Skip to content

Commit

Permalink
Document Destroy Async (#41680)
Browse files Browse the repository at this point in the history
* Document Destroy Async
Motivation:
  - Add docs for Destroy async. I think I probably need to add
    information about setting up active job, but I am not sure where we
    want this, so I am putting this together to start conversation.

Related Issues:
  - #41093

* Active Job not ActiveJob

* Fix some spelling issues

[Cory Gwin, Rafael Mendonça França, Eileen M. Uchitelle, Henrik Nyh]
  • Loading branch information
gwincr11 committed Mar 24, 2021
1 parent 89719d4 commit 96b3d5a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion guides/source/association_basics.md
Expand Up @@ -1011,6 +1011,9 @@ If you set the `:dependent` option to:
associated objects.
* `:delete`, when the object is destroyed, all its associated objects will be
deleted directly from the database without calling their `destroy` method.
* `:destroy_async`: when the object is destroyed, an `ActiveRecord::DestroyAssociationAsyncJob`
job is enqueued which will call destroy on its associated objects. Active Job must be set up
for this to work.

WARNING: You should not specify this option on a `belongs_to` association that is connected with a `has_many` association on the other class. Doing so can lead to orphaned records in your database.

Expand Down Expand Up @@ -1312,6 +1315,7 @@ Controls what happens to the associated object when its owner is destroyed:

* `:destroy` causes the associated object to also be destroyed
* `:delete` causes the associated object to be deleted directly from the database (so callbacks will not execute)
* `:destroy_async`: when the object is destroyed, an `ActiveRecord::DestroyAssociationAsyncJob` job is enqueued which will call destroy on its associated objects. Active Job must be set up for this to work.
* `:nullify` causes the foreign key to be set to `NULL`. Polymorphic type column is also nullified on polymorphic associations. Callbacks are not executed.
* `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there is an associated record
* `:restrict_with_error` causes an error to be added to the owner if there is an associated object
Expand Down Expand Up @@ -1632,7 +1636,7 @@ The [`collection.clear`][] method removes all objects from the collection accord
@author.books.clear
```

WARNING: Objects will be deleted if they're associated with `dependent: :destroy`,
WARNING: Objects will be deleted if they're associated with `dependent: :destroy` or `dependent: :destroy_async`,
just like `dependent: :delete_all`.

##### `collection.empty?`
Expand Down Expand Up @@ -1768,6 +1772,7 @@ Controls what happens to the associated objects when their owner is destroyed:

* `:destroy` causes all the associated objects to also be destroyed
* `:delete_all` causes all the associated objects to be deleted directly from the database (so callbacks will not execute)
* `:destroy_async`: when the object is destroyed, an `ActiveRecord::DestroyAssociationAsyncJob` job is enqueued which will call destroy on its associated objects. Active Job must be set up for this to work.
* `:nullify` causes the foreign key to be set to `NULL`. Polymorphic type column is also nullified on polymorphic associations. Callbacks are not executed.
* `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there are any associated records
* `:restrict_with_error` causes an error to be added to the owner if there are any associated objects
Expand Down

0 comments on commit 96b3d5a

Please sign in to comment.