我試圖軟刪除一個完整的Customer
。 A Customer
延伸User
。 Customer
也有關聯的InvoiceAddress[]
實體。ZF2,Doctrine2,Gedmo - SoftDelete JTI實體與協會
但是,它不起作用。如果Customer
的值爲@Gedmo\SoftDeleteable
,則在與外部密鑰關聯User
上失敗。如果我也使User
實體軟刪除,那麼它在Customer
和InvoiceAddress
之間的關聯上失敗。
如果我做出cascade={"persist", "remove"}
(加remove
)Customer
和InvoiceAddress
之間的關係,那麼它很難刪除相關Customer
所有實體。
我想它可能是在配置上,雖然有readmultiplequestions和SoftDeleteable擴展本身的(當然),我還沒有想出什麼/在哪裏我做錯了。
下面是我的設置,我已經從與問題無關的代碼中刪除了東西。
Customer
.PHP
namespace Customer\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\SoftDeleteable\SoftDeleteable;
// moar
/**
* @ORM\Table
* @ORM\Entity
*
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Customer extends User implements SoftDeleteable
{
use GedmoDeletedAtTrait;
/**
* @var ArrayCollection|InvoiceAddress[]
* @ORM\OneToMany(targetEntity="Customer\Entity\InvoiceAddress", mappedBy="customer", cascade={"persist"}, fetch="EAGER")
*/
protected $invoiceAddresses;
// properties, __construct(){}, getters/setters...
}
User
.PHP
namespace User\Entity;
use BjyAuthorize\Provider\Role\ProviderInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Mvc\Entity\AbstractEntity;
use ZfcUser\Entity\UserInterface;
/**
* @ORM\Table
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
*/
class User extends AbstractEntity implements UserInterface, ProviderInterface
{
// properties, constructor, getters/setters...
}
GedmoDeletedAtTrait
.PHP
namespace Mvc\Traits;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
trait GedmoDeletedAtTrait
{
use SoftDeleteableEntity;
/**
* Note: overrides Annotation (column name) and type hint, else it's the same as the original
*
* @var \DateTime|null
* @Doctrine\ORM\Mapping\Column(name="deleted_at", type="datetime", nullable=true)
*/
protected $deletedAt;
}
學說模塊配置爲客戶模塊
'doctrine' => [
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver',
'cache' => 'array',
'paths' => [
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'Entity',
]
],
'orm_default' => [
'drivers' => [
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
],
],
],
'eventmanager' => [
'orm_default' => [
'subscribers' => [
SoftDeleteableListener::class,
],
],
],
],
相關問題:the docs還提到 「過濾器」。如何在上面的設置中實現它們並在整個模塊中使用它們?