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.

SoftDelete behavior doesn't work on Phalcon 2.0.2

I did it on Phalcon 1.3.x but can't do on 2.0.2 branch

<?php
// model
class Directories extends Model
{
    // ...
    public function initialize()
    {
        $this->addBehavior(new SoftDelete(
            [
                'field' => 'active',
                'value' => 0,
            ]
        ));
    }
    // ...
}

// and use
Directories::findFirst(1)->delete();

If I remove initialize method, mysql logs show me such queries:

389 Query   DESCRIBE `directories`
389 Query   SELECT `directories`.`id`, `directories`.`user_id`, `directories`.`parent_id`, `directories`.`name`, `directories`.`active` FROM `directories` WHERE `directories`.`id` = 1 LIMIT 1
389 Query   DELETE FROM `directories` WHERE `id` = '1'
389 Quit

But if I return method, mysql logs show me such queries:

390 Query   DESCRIBE `directories`
390 Query   SELECT `directories`.`id`, `directories`.`user_id`, `directories`.`parent_id`, `directories`.`name`, `directories`.`active` FROM `directories` WHERE `directories`.`id` = 1 LIMIT 1
390 Quit

What's the problem?



48.4k
Accepted
answer

Try my SoftDelete Behavior. There is a Behavior and Trait. The Behavior is ported and extended from Phalcon 2 and the Trait adds some features to it for PHP 5.4+.