Question

My DB structure is as follows:

work:

  • CTI table Work
  • MappedSuperclass table AbstractImageWork which extends Work
  • final table PhotoWork which extends AbstractImageWork

comment:

WorkComment has a ManyToOne relation to Work:

@ManyToOne(targetEntity="Work", inversedBy="comments")

Work has a OneToMany relation to WorkComment:

@OneToMany(targetEntity="WorkComment", mappedBy="work")

The problem is that Doctrine gives me this error while updating the schema:

[Doctrine\ORM\Mapping\MappingException]
It is illegal to put an inverse side one-to-many or many-to-many association on
mapped superclass 'Acme\...\AbstractImageWork#comments'.

I guess this has something to do with the MappedSuperclass AbstractImageWork stuck in the middle between Work and PhotoWork, but I didn't actually put this relation on the MappedSuperclass, but on the CTI table.. so why will Doctrine behave like this?

Any ideas?

Was it helpful?

Solution

In some cases, when you have such error when inherit from the class that is tagged as @ORM\MappedSuperclass, try to change your properties access level from private to protected

OTHER TIPS

In others cases happens when you declare @ORM\Entity in an abstract superior class instead of @ORM\MappedSuperclass

A mapped superclass cannot be an entity, it is not query-able and persistent relationships defined by a mapped superclass must be unidirectional (with an owning side only). This means that One-To-Many associations are not possible on a mapped superclass at all. Furthermore Many-To-Many associations are only possible if the mapped superclass is only used in exactly one entity at the moment. For further support of inheritance, the single or joined table inheritance features have to be used.

Check it out here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top