gpt4 book ai didi

php - StofDoctrineExtensionsBundle softdelete - 我该如何使用它?

转载 作者:可可西里 更新时间:2023-11-01 12:22:37 25 4
gpt4 key购买 nike

我的老板为软删除过滤器安装了这个包,但是 documentation是稀疏的。如何在我的删除查询中使用它?

最佳答案

在你的配置中启用它:

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

关于php - StofDoctrineExtensionsBundle softdelete - 我该如何使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16670454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com