-
-
Notifications
You must be signed in to change notification settings - Fork 57
MissingDependentDestroyChecker
Evgeniy Demin edited this page Dec 3, 2025
·
2 revisions
This checker identifies cases where a belongs_to association is backed by a foreign key without an on_delete option. While the foreign key enforces data integrity by preventing orphaned records, attempting to delete the parent object will raise an error due to the database constraint.
To avoid such errors and handle deletions gracefully, you should either:
- Add a
dependent::destroy,:delete,:delete_all, or:nullifyoption to the correspondinghas_oneorhas_manyassociation. - Set the foreign key's
on_deleteoption tocascadeornullify.
Use case example:
class User
has_many :posts
end
class Post
belongs_to :user
end
# schema.rb
add_foreign_key "posts", "users"If the project helps you or your organization, I would be very grateful if you contribute or donate. Your support is an incredible motivation and the biggest reward for my hard work.
- Home
- Installation
- How to run?
- Configuration
- Auto correction
- Integrations
- Implementing Custom Checker
- Checkers
- ColumnPresenceChecker
- LengthConstraintChecker
- NullConstraintChecker
- UniqueIndexChecker
- ForeignKeyChecker
- MissingUniqueIndexChecker
- MissingIndexChecker
- PrimaryKeyTypeChecker
- ForeignKeyTypeChecker
- RedundantIndexChecker
- RedundantUniqueIndexChecker
- EnumTypeChecker
- ForeignKeyCascadeChecker
- EnumValueChecker
- CaseSensitiveUniqueValidationChecker
- ThreeStateBooleanChecker
- MissingAssociationClassChecker
- MissingTableChecker
- ImplicitOrderingChecker
- MissingDependentDestroyChecker
- FAQ
- Development