README.md in dependent-auto-rails-0.2.0 vs README.md in dependent-auto-rails-0.2.1

- old
+ new

@@ -1,22 +1,24 @@ [![Version](https://img.shields.io/gem/v/dependent-auto-rails)][badges:0-gem] [![Build](https://img.shields.io/github/actions/workflow/status/joshuay03/dependent-auto-rails/.github/workflows/main.yml?branch=main)][badges:1-workflow] # dependent-auto-rails -This gem provides a new `dependent` option for ActiveRecord associations, `:auto`. Using this option will automatically select between `:destroy` and `:delete` / `:delete_all` during runtime based on whether or not the associated model has any callbacks defined which would usually be executed as part of the destroy lifecycle. This is useful since `dependent: :destroy` always initialises the associated records in order to execute their callbacks regardless of whether or not there are any defined, but is often the go-to option since it is the safest. This can be expensive if there are many records to destroy. +This gem provides a new `dependent` option for ActiveRecord associations, `:auto`. Using this option will automatically select between `:destroy` and `:delete` / `:delete_all` during runtime based on whether or not the associated model has any callbacks defined which would usually be executed as part of the destroy lifecycle. +This is useful since `dependent: :destroy` always initialises the associated records in order to execute their callbacks regardless of whether or not there are any defined, but is often the go-to option since it is the safest. This can be expensive if there are many records to destroy. + It is also useful since a model's associations are rarely updated, but it's business logic can change frequently. This means that if destroy callbacks are added or removed on the associated model, the `dependent` option on the parent model's association may need to be updated to reflect this. Using `dependent: :auto` will automatically select the appropriate `dependent` option based on the current state of the model. -If you're looking for a solution with little less magic, check out https://github.com/gregnavis/active_record_doctor's `incorrect_dependent_option` detector. - **NOTE**: The `:auto` option **ONLY** decides between `:destroy` and `:delete` / `:delete_all`. It does not use any of the other `dependent` options: - `:nullify` - `:destroy_async` - `:restrict_with_error` - `:restrict_with_exception` **NOTE**: If for some reason the `:auto` option is unable to decide between `:destroy` and `:delete` / `:delete_all`, it will default to `:destroy`. + +**INFO**: If you're looking for a solution with a little less magic, check out the `incorrect_dependent_option` detector provided by https://github.com/gregnavis/active_record_doctor. ## Installation Install the gem and add it to the application's Gemfile by executing: