model.relation.beforeAttach

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

Called before creating a new relation between models (only for BelongsToMany relation)

Example usage:

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