I am using Gedmo extension in addition with Symfony 3.2 and Doctrine 2.5.6 and I'm encountering an issue. I can't make Gedmo\Blameable and UniqueEntity constraint work together. Indeed, the blamed field is still null at validation time. Is there any way to make it work or a possible work-around ?
Here is my entity
/**
* @UniqueEntity(
* fields={"author", "question"},
* errorPath="question",
* message="This author already has an answer for that Question"
* )
* @ORM\Entity
*/
class TextAnswer
{
/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* @Gedmo\Blameable(on="create")
*/
private $author;
/**
* @Assert\NotNull()
* @ORM\ManyToOne(targetEntity="Question", inversedBy="textAnswers")
* @ORM\JoinColumn(name="question_id", referencedColumnName="id")
*/
private $question;
}
Thanks
EDIT : SOLUTION
Rather than manually setting the user (which removes Gedmo\Blameable interests), I created my own entity validator. I give it doctrine and token storage as arguments so it can make a query on db to validate my criteria with the currently connected user (that will be later used by Gedmo\Blameable).
The BlameableListener
is invoked during the Doctrine's flush operation, which normally happens after the entity has been validated. That's why $author
is null
at validation time.
The most straightforward workaround is to set $author
yourself beforehand.