Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Doctrine SoftDelete - Include deleted records?

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

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

Something like this would be useful as for most queries I want deleted records excluded, but sometimes (for example, to administrators) I want to be able to include records that have been soft deleted. Is there some good way to do this with SoftDelete or should I simply add an additional where clause onto most queries?

like image 975
Wickethewok Avatar asked Sep 01 '09 19:09

Wickethewok


2 Answers

It returns all records from table (include 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();
}
like image 67
factorlabs Avatar answered Nov 15 '22 11:11

factorlabs


Looks like you may disable soft-deleteable filter http://atlantic18.github.io/DoctrineExtensions/doc/softdeleteable.html

// This will disable the SoftDeleteable filter, so entities which were "soft-deleted" will appear in results $em->getFilters()->disable('soft-deleteable');

like image 39
rhaps107 Avatar answered Nov 15 '22 11:11

rhaps107