Answer the question
In order to leave comments, you need to log in
How to implement correct deletion of related data in Symfony?
Hello!
I can not decide in any way how to implement a prohibition on deleting a record with a warning / exception.
I have two entities
List.php
/**
* @ORM\ManyToOne (targetEntity="Download\Entity\Status", inversedBy="request")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
protected $status;
Status.php
/**
* @ORM\OneToMany(targetEntity="Download\Entity\List", mappedBy="status",
* cascade={"persist"}, orphanRemoval=true)
*/
protected $request;
Answer the question
In order to leave comments, you need to log in
You can try otherwise - make a deletion method at the level of some service, before deleting check for the presence of related entities (select /exists), if found - throw an exception with a warning. It seems to me that at the level of a standard annotation, this simply will not work, additional measures are needed)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question