Search code examples
phpsymfonydoctrine-ormdoctrinedoctrine-1.2

Automatically filter out rows that don't meet a condition in Doctrine


I have a database already in use and I can't really change it. On this database I use a "soft delete": instead of actually deleting a record, I just modify a flag (e.g. setting del=1).

I don't use the GEDMO template (SoftDelete) but I want the same functionality. Currently when I use QueryBuilder/find functions, they return records with del=1. Same idea on association entities' functions; I have to check every time if del=0.

Is there a way to automatically filter out records with flag del=1, unless it's explicitly requested?


Solution

  • you probably can use doctrine filters:

    http://doctrine-orm.readthedocs.org/en/latest/reference/filters.html http://www.michaelperrin.fr/2014/07/25/doctrine-filters/

    to disable:

    http://doctrine-orm.readthedocs.org/en/latest/reference/filters.html#disabling-enabling-filters-and-setting-parameters