I have problem with relation Many to One to MappedSuperclass in Symfony 5. I have entities Employee, Employer which extends MappedSuperclass abstract class Person. And I want create raports entity which will be in relation with Person (both Employee and Employer) like below:
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*/
private $person;
But when i try to push migrations I get following error message:
Column name
id
referenced for relation from App\Entity\Raport towards App\Entity\Person does not exist.
but I have id properties in these classes:
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
I found on the Symfony page example with creating interface to do it but it doesn't work for me too. Maybe someone had that problem before and know how to resolve it. Thanks a lot for any reply.
EDIT My Person class:
**
* Abstract base class to be extended by my entity classes with same fields
*
* @MappedSuperclass
*/
abstract class Person
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id; //This property exist in Employee and Employer too (like doctrine documentation said)
Now when I change it from superclass to 'JOINED' inheritance when I try create now Employee or Employer I get following error:
An exception occurred while executing 'INSERT INTO person (discr) VALUES
(?)' with params ["Employee"]:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i
n your SQL syntax; check the manual that corresponds to your MySQL server v
ersion for the right syntax to use near 'person (discr) VALUES ('Employee')'
at line 1
There isn't any other way to just make relation in one property to few entities whose implements one interface or extends class?? Sometimes I hate doctrine... And my person entity maybe it helps configure what is wrong:
* @ORM\Entity(repositoryClass=PersonRepository::class)
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"person" = "Person", "employee" = "Employee", "employer" = "Employer"})
*/
class Person
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
public function getId(): ?int
{
return $this->id;
}
}