My boss installed this bundle for the softdelete filter, but the documentation is beyond sparse. How do I use this in my delete queries?
Asked
Active
Viewed 1.0k times
11
-
4The documentation is not beyond sparse. StofDoctrineExtensionsBundle is only the integration of the [Doctrine Extenssions](https://github.com/l3pp4rd/DoctrineExtensions) for Symfony. So look there for the [softdeleteable documentation](https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md) – Emii Khaos May 21 '13 at 13:33
2 Answers
46
Enable it in your config:
stof_doctrine_extensions:
orm:
default:
...
softdeleteable: true
doctrine:
...
orm:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
Then in your entity:
<?php
namespace Foo\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* ...
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
* @ORM\Entity
*/
class Foo
{
/**
* @var \DateTime $deletedAt
*
* @ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
private $deletedAt;
Then just delete entities like you normally would (the extension takes care of the rest):
$em = $this->getDoctrine()->getManager();
$em->remove($entity);
$em->flush();

Thomas K
- 6,076
- 5
- 39
- 56
-
6Thank you very much. They did not put those instructions in the docs! – Joe Yahchouchi Jan 30 '16 at 18:19
-
4I have a related question: Once you `remove` an entity, it gets a `deletedAt` timestamp and it doesn't show up in a normal `find` query, which is fine. But, what if I want to access the deleted timestamp for some other use? Is manually disabling the filter, getting the data, and re-enabling it the only option? Seems a little dirty and possibly unsafe. – aalaap Oct 21 '16 at 10:02
1
I also needed another puzzle part: The doctrine yaml config:
XYBundle\Entity\Adresse:
type: entity
table: adresse
gedmo:
soft_deleteable:
field_name: deleted_at
time_aware: false
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
ort:
type: string
length: 100
plz:
type: string
columnDefinition: varchar(255) NOT NULL DEFAULT ''
deleted_at:
type: datetime
nullable: true

Benjamin
- 961
- 1
- 11
- 23