My boss installed this bundle for the softdelete filter, but the documentation is beyond sparse. How do I use this in my delete queries?
StofDoctrineExtensionsBundle softdelete - How do I use it?
Asked Answered
The documentation is not beyond sparse. StofDoctrineExtensionsBundle is only the integration of the Doctrine Extenssions for Symfony. So look there for the softdeleteable documentation –
Avouch
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();
Thank you very much. They did not put those instructions in the docs! –
Epicycle
I 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. –
Redhead 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
© 2022 - 2024 — McMap. All rights reserved.