We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

[Resolved] Autofilter softdeleted records

I looked through the first 20+ pages of discussion and performed some searching but could not find an answer.

I'm doing soft deletes on my models. I'd like to not show those deleted records by default within the model so I don't have to filter each time I query. What is the proper approach for this? Where do I specify that I want: (deleted is null) or (deleted = 0) in my query each time so that it does not prohibit me from searching/filtering within the application?


edited Feb '15

I believe you would need to extend the Model class and impliment your own functions E.G.

class ExtendedModel extends \Phalcon\Mvc\Model
    public static function myFind($array)
        $array[0] .= ' AND deleted = 0';
        return self::find($array);

    //etc for findFirst, count, max

class Users extends ExtendedModel
    public $id;
    public $deleted;

    'id = :id',
    'bind' => ['id' => 1]

Interesting. I'll take this approach and see what comes of it.