Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

error: Record is referenced by model

I would like delete records but I get error message

Record is referenced by model XXXXXXX

this model is belongTo other models but I can't delete related records because beforeDelete not trigger. Function _checkForeignKeysRestrict is execute before beforeDelete and breaking deletion process.

How can solve it?



54.4k
Accepted
answer
        $this->hasMany(
            "id",
            "Parts",
            "robots_id",
            [
                "foreignKey" => [
                    "action" => Relation::ACTION_CASCADE,
                ]
            ]
        );

https://olddocs.phalconphp.com/en/latest/reference/model-relationships.html#cascade-restrict-actions

Thanks for tips. I had an option set "foreignKey" => true. After remove working properly.