Skip to content

Auto add better constraint actions #385

@dereuromark

Description

@dereuromark

This is a (multiple allowed):

  • enhancement

  • CakePHP Version: latest

What you did

Deleting a parent of child, that do not have "depending=>true" relationship.
As such, the foreign_key was still the old id, we just removed.
Now there is an invalid foreign key set that doesnt exist as row anymore.

Expected Behavior

When generating migrations (bake task and otherwise):

'delete' => 'SET_NULL' for addForeignKey()
should be auto-set for such "NULLable" fields that have no such depending constraint.
This would make sure the foreign_key here is set to NULL again and when we query for all that have no relation to that parent we would also find the right entities.

Example code

    $this->table('releases')
        ->addForeignKey('release_element_id', 'release_elements', ['id'], ['delete' => 'SET_NULL'])
        ->update();

For a DEFAULT NULL relation here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions