5

I'm trying to combine Doctrine's Extensions Blameable and Softdeleteable: when I execute $em->remove($myEntity);, I want to get the fields deleted and deletedBy updated accordingly.

use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @Gedmo\SoftDeleteable(fieldName="deleted", timeAware=false)
 */

[...]

/**
 * DateTime of softdeletion
 * @var \DateTime
 * 
 * @ORM\Column(name="deleted", type="datetime", nullable=true)
 * @Assert\DateTime()
 */
private $deleted;

/**
 * Softdeleted by
 * @var MyProject\UserBundle\Entity\User $deletedBy
 *
 * @Gedmo\Blameable(on="change", field="deleted")
 * @ORM\ManyToOne(targetEntity="MyProject\UserBundle\Entity\User")
 * @ORM\JoinColumn()
 */
private $deletedBy;

I have a similar configuration for created/createdBy (with Blameable(on="create")) and updated/updatedBy (with Blameable(on="update")).

Even weirder, if I replace the code above by the one below, the field deletedBy is correctly updated:

/**
 * Softdeleted by
 * @var MyProject\UserBundle\Entity\User $deletedBy
 *
 * @Gedmo\Blameable(on="update")
 * @ORM\ManyToOne(targetEntity="MyProject\UserBundle\Entity\User")
 * @ORM\JoinColumn()
 */
private $deletedBy;

So it seems that it is only the Blameable(on="change", field="deleted") part which doesn't work, and I have no idea why...

Blacksad
  • 1,230
  • 1
  • 14
  • 23

0 Answers0