I have two entities which are below :-
- Website
- Posts
In the website entity, I have given OneToMany
relation, And in the posts entity, I have given the ManytoOne
relation.
Website Entity:-
/**
* @var Collection<Post>
*
* @ORM\OneToMany(targetEntity="App\Domain\Entity\Post\Post", mappedBy="website", cascade={"all"})
*/
private Collection $posts;
Post Entity:-
/**
* @ORM\ManyToOne(targetEntity="App\Domain\Entity\Website\Website", inversedBy="posts")
* @ORM\JoinColumn(name="website_id", referencedColumnName="id", onDelete="SET NULL")
*/
private ?Website $website = null;
The issue is that when I deleting a website so relevant all the posts of the website are deleted, but I want to keep the associated posts of the website (which I have deleted website).