10

我的老板为 softdelete 过滤器安装了这个包,但文档非常稀少。如何在删除查询中使用它?

4

2 回答 2

46

在您的配置中启用它:

stof_doctrine_extensions:
    orm:
        default:
            ...
            softdeleteable: true

doctrine:
    ...
    orm:
        filters:
            softdeleteable:
                class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                enabled: true

然后在您的实体中:

<?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;

然后像往常一样删除实体(扩展负责其余部分):

    $em = $this->getDoctrine()->getManager();
    $em->remove($entity);
    $em->flush();
于 2013-05-21T13:21:38.633 回答
1

我还需要另一个谜题部分:教义 yaml 配置:

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
于 2016-11-15T21:43:17.697 回答