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

phalcon softDelete : how to find

Hi,

I have successfully configured below softDelete and It works fine. But the find() method returns all the records. Do I need to override find() method to find([[ is_deleted => 0 ]]) ?

public function initialize() {
$this->addBehavior(new SoftDelete(
    array(
        'field' => 'is_deleted',
        'value' => 1
    )
)); 
}


1.4k
edited Feb '19

When you use softdelete - you not delete rows in reallity. So you can't use :beforeDelete and :afterDelete. If you want find all "softdeleted" rows - you can do it:

Model::find("is_deleted=1");

or

Model::find(
    [
        'conditions' => 'is_deleted = ?1',
        'bind'       => [
            1 => 1,
        ]
    ]
);