PHP Doctrine SoftDelete - enable deleted records?

If I have one of my PHP Doctrine objects act like SoftDelete, is it possible to include deleted elements in the results of certain queries? I'm looking for something like this ...

$q = Doctrine_Query::create()
    ->select('*')
    ->from('Test t')
    ->where('id < ?', 25)
    *->includeDeleted()*;

Something like this would be useful, since for most requests I want deleted entries to be excluded, but sometimes (for administrators, for example) I want to be able to include entries that were gently deleted. Is there a good way to do this with SoftDelete, or just add an extra where clause to most queries?

+3
source share
5 answers

, , -, SoftDelete. where , .

(, , , Doctrine_Query , , Doctrine_Record. Doctrine_Query, includeDeleted(), , :))

+2

( softDeleted)

public function findAllWithDeleted()
{
    $query = $this->createQuery('a');
    $query->addWhere('(a.deleted_at IS NULL OR a.deleted_at IS NOT NULL)');
    return $query->execute();
}
+3

Doctrine 1.2.2, ATTR_USE_DQL_CALLBACKS , softdelete . , :

$m = new MyModel;
$m->setListener(new MockListener());
$m->getTable()->getQueryObject(); //... and so forth

:

class MockListener implements Doctrine_Overloadable
{
    public function __call($m, $a){}
}
+1
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false);

, , softDelete.

+1

It looks like you can disable the soft-deleted filter http://atlantic18.imtqy.com/DoctrineExtensions/doc/softdeleteable.html

// This will disable the SoftDeleteable filter, so objects that have been "softly deleted" will be displayed in the results $ -> getFilters () → disable ('soft deleteable');

0
source

Source: https://habr.com/ru/post/1716625/


All Articles