We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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?



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

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

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