Skip to content

ForeignKeyCascadeChecker

Evgeniy Demin edited this page Nov 28, 2022 · 1 revision

Imagine, you have an association with :dependent option. It means that every time you the record is destroyed, the application expects associated data to be also affected depending on the option.

Unfortunately, as such a dependency call is based on the callbacks, it could be simply skipped. Meaning, our expectations wouldn't be met. Gladly, some of the options can be easily fixed by introducing corresponding cascade constraints on foreign keys on the database level.

Currently, supported options are:

  • delete
  • delete_all
  • nullify
  • restrict_with_exception
  • restrict_with_error

There is nothing to be done with destroy or destroy_async options because database deletion can't invoke application callbacks.

In case callbacks are not important, we highly recommend using delete/delete_all options instead.

Clone this wiki locally