Skip to content

Implement Proper on_delete Behavior for ForeignKey Fields #40

@ProdByGodfather

Description

@ProdByGodfather

Description

Currently, the ForeignKey field in our ORM does not properly enforce on_delete behaviors (CASCADE and SET NULL). When a record with a foreign key reference is deleted, related records are not affected as expected.

Expected Behavior

  • If on_delete='CASCADE', all related records in the foreign key table should be deleted.
  • If on_delete='SET NULL', the foreign key field in related records should be set to NULL.

Current Issue

  • Deleting a record does not propagate changes to related records.
  • Foreign key constraints do not properly handle cascading deletes or nullifying references.

Proposed Solution

Modify the delete method to:

  1. Identify related ForeignKey fields before deletion.
  2. Apply the correct behavior (CASCADE or SET NULL) to related records before executing the delete query.
  3. Ensure consistency across related models.

Metadata

Metadata

Labels

bugSomething isn't workingenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions