'Not able to delete an entity that extends another using DiscriminatorColumn due to foreign key constraint

I am using @ORM\InheritanceType("JOINED") on my User class and i’ve created an Agent class which extends User

When I try to delete the Agent entry or the corresponding User entr, I get a foreign key constraint error

How can I add orphan removal?

This are my User class entity settings:

/**
 * @ORM\Entity(repositoryClass=UserRepository::class)
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({"agent" = "Agent", "user" = "User"})
 * @ORM\HasLifecycleCallbacks
 */


Solution 1:[1]

It seems a "hacky" solution but i've added this code to my delete agent controller code:

$user = $this->userRepository->find($agent->getId());

$this->entityManager->remove($user);
$this->entityManager->remove($agent);
$this->entityManager->flush();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ste