model.relation.beforeDetach

Triggered in October\Rain\Database\Relations\BelongsToMany.

Called before removing a relation between models (only for BelongsToMany relation)

Example usage:

$model->bindEvent('model.relation.beforeDetach', function (string $relationName, array $attachedIdList) use (\October\Rain\Database\Model $model) {
    if (!$model->isRelationValid($attachedIdList)) {
        throw new \Exception("Invalid relation!");
        return false;
    }
});