phalcon / phalcon/cphalcon

[BUG]: Model events manager on beforeDelete with softdelete

Open
#16,980 8 comments 0 reactions 1 assignee View on GitHub

@niden is already working on this.

Since May 4, 2026.

  • #15163 by @jenovateurs — merged
  • #15183 by @Jeckerson — merged
7.0 bug discussion
Dominant language
PHP
Stars
10.8k
Forks
1.9k
Avg merge
7h 2m
Merged PRs (30d)
47

Description

Describe the bug
If softDelete is enabled and there is event model:beforeDelete, it executes DELETE (in that case UPDATE) even if attached anonymous function returns false.

To Reproduce
Steps to reproduce the behavior:

<?php

use Phalcon\Events\Event;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Model\Behavior\SoftDelete;

class User extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        /** @var Manager $eventsManager */
        $eventsManager = $this->getDI()->getShared('eventsManager');
        $eventsManager->attach('model:beforeDelete', function (Event $event, $model) {
            return false;
        });

        $this->addBehavior(new SoftDelete([
            'field' => 'deleted_at',
            'value' => date('Y-m-d H:i:s'),
        ]));
    }
}

Expected behavior
It does not mark deleted_at with current date time if event returns false.

Details

  • Phalcon version: 4.0.5
  • PHP Version: 7.4.3
  • Operating System: Ubuntu
  • Installation type: Compiling from source
  • Zephir version (if any):
  • Server: Nginx
  • Other related info (Database, table schema): MySQL

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.