Delete entities by specification
peter-gribanov opened this issue · 2 comments
peter-gribanov commented
It would be nice to have a method for deleting entities according to the specification.
$rep->delete(Spec::in('id', $ids));
$rep->delete(Spec::orX(
Spec::eq('enabled', false),
Spec::lt('create_at', new \DateTime('-3 month'))
));
peter-gribanov commented
Simple implementation
public function delete(Specification $spec)
{
$qb = $this->createQueryBuilder($this->alias);
$this->applySpecification($qb, $specification);
$qb->delete();
return (bool) $qb->getQuery()->execute();
}
peter-gribanov commented
We will not do the short method, but the problem can be solved through the QueryBuilder:
$rep
->getQueryBuilder($spec)
->delete()
->getQuery()
->execute()
;