Question

My boss installed this bundle for the softdelete filter, but the documentation is beyond sparse. How do I use this in my delete queries?

Was it helpful?

Solution

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();

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top