Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StofDoctrineExtensionsBundle softdelete - How do I use it?

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

like image 942
Major Productions Avatar asked May 21 '13 12:05

Major Productions


1 Answers

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();
like image 91
Thomas K Avatar answered Oct 22 '22 19:10

Thomas K