I have two entities : Document and DocumentValidation
Document :
class Document
{
...
/**
* @ORM\OneToMany(
* targetEntity="AppBundle\Entity\DocumentValidation",
* mappedBy="document",
* cascade={"persist"}
* )
*/
private $validations;
DocumentValidation :
class DocumentValidation
{
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
* @Assert\DateTime
*/
private $validatedAt;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
* @Assert\DateTime
*/
private $deletedAt;
Each Document can validated and deleted many times. But a document can only have one validation in progress : Validation, deletion, validation, deletion, validation, deletion, validation, ...
In Twig, I list all Documents. And I want to check if each document can be deletable. If a document has a validation in progress, it can not be deleted and hide delete icon.
What is the best method ?
- If I use Doctrine query in Symfony Voter with is_granted() for check if each document has validation in progress, I have many many many queries ... (one per Document) ;
- If I use LEFT JOIN in Controller (and Symfony Voter), it's very difficult if I have many controls (read [PLEASE] at below ) ;
- Create a Class with Filesystemcache and save if each Document can be deleted. Regenerate the cache at each linked entity manipulation ;
- Other ?
PLEASE, keep in mind that this situation is very simple. In my situation, I have many reasons (> 10) to reject a deletion or modification, almost always because of a relationship in database