0

我正在使用 soft-Deletable 扩展,一切正常,除了 1 件事。

当我做以下等于真(伪代码):

null == $fooRepository->findByCriteria('criteria to find deleted entity');

但以下等于假

null == $otherEntity->getDeletedFooEntity()

当我这样做时

if ($otherEntity->getDeletedFooEntity() != null)
{
    $var = $otherEntity->getDeletedFooEntity()->getAnyProperty();
}

我收到服务器 500 错误:找不到实体

我怎样才能使它返回null?还是我做错了?

非常感谢

4

2 回答 2

0

如果您对已删除的实体使用唯一索引,Gedmo 就会遇到问题。您可以通过在软删除实体时更改值来避免这种情况。在这里,您可以在我写的一篇文章中详细了解如何执行此操作:http: //www.intelligentbee.com/blog/2015/01/09/symfony2-gedmo-softdeletable-doctrine-entities-with-unique-index -列/

于 2015-01-26T15:32:35.553 回答
0

要回答 500 错误,您可以这样修改代码:

if ($otherEntity->getDeletedFooEntity() instanceOf Foo) {
    $var = $otherEntity->getDeletedFooEntity()->getAnyProperty();
}

其中 Foo 是应该由“getDeletedFooEntity”方法返回的类。

于 2014-09-29T08:50:54.107 回答