php - Symfony 软删除

标签 php symfony doctrine-orm

我有实体并且我使用

* @Gedmo\SoftDeleteable(fieldName="deletedAt")

当我删除数据库中的某些实体时,我的实体和字段已删除。当我删除实体时,我有时间,这是可以的。但现在我需要找到所有deleteAt实体?我创建 QB

$qb = $this->getEntityManager()->createQueryBuilder('d');
$qb
    ->select('d')
    ->from('ArtelProfileBundle:Project', 'd')
    ->where('d.deletedAt IS NOT NULL');

$count = $qb->getQuery()->getResult();
$query = $qb->getQuery();
$results = $query->getResult();
return [$results, $count];

我有 0 个实体,为什么以及如何找到实体?

更新 在我的 Controller 中

class ProjectController extends FOSRestController
{
public function getProjectsAction(ParamFetcher $paramFetcher)
{
$manager = $this->getDoctrine()->getManager();
        if($paramFetcher->get('status'))
    {
        $manager->getFilters()->disable('soft-deleteable');
        $queryBuilder = $manager->getRepository('ArtelProfileBundle:Project')->findForStatusProject($paramFetcher, $this->getUser());
    }

我有错误

 Filter 'soft-deleteable' is not enabled.

我的实体

/**
 * Project
 *
 * @ORM\Table(name="project")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 * @ORM\Entity(repositoryClass="Artel\ProfileBundle\Entity\Repository\ProjectRepository")
 * @ExclusionPolicy("all")
 */
class Project
{
/////
/**
 * @var \DateTime $deletedAt
 *
 * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
 * @Type("DateTime")
 * @Expose()
 */
protected $deletedAt;

请帮忙

最佳答案

已解决 这只是我在配置中使用的名称与代码中使用的名称不匹配

        filters:
        softdeleteable:
            class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
            enabled: true
stof_doctrine_extensions:
default_locale: "%locale%"
orm:
    default:
        timestampable: true
        sluggable:     true
        softdeleteable: true

然后我会采取行动

$manager->getFilters()->disable('softdeleteable');

并拥有我删除的实体

关于php - Symfony 软删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32862630/

相关文章:

php - 将php变量放入mysql查询

php - RabbitMqBundle 消费者退出时出现异常 "Error reading data. Received 0 instead of expected 1 byte"和 "Broken pipe or closed connection"

symfony - Doctrine :级联 ="remove"与 orphanRemoval=true

php - Laravel 8 : QueueManager. php:156 类型为空的数组偏移量/配置redis

doctrine-orm - 在供应商/autoload.php 中找不到 Composer/Doctrine 2 类 'ComposerAutoloaderInit...'

php - Doctrine2 应该自动合并相关实体

orm - Symfony2 - 学说 :create in Production

javascript - 用php还是js显示数据?

PHP - 为什么我的幻灯片只读取 1 张图像?

javascript - 如何使用 jquery 永久添加元素,然后它会逐渐添加数字,例如 Cam 1、Cam 2、Cam 3 等。使用 iframe