我的老板为软删除过滤器安装了这个包,但是documentation超出了稀疏范围。如何在删除查询中使用它?
答案 0 :(得分:39)
在您的配置中启用它:
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();
答案 1 :(得分:1)
我还需要另一个拼图部分:教义yaml config:
ANWISBundle\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