3

I am trying to update my database schema but I am getting following error:

  [Doctrine\ORM\Mapping\MappingException]                                                                                                        
  It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass 'AppBundle\Entity\ListContent#attachments'.

I have following entity hierarchy:

Content entity is concrete class for Single table inheritance where I store all of my content eg. Page, Blog, etc.

In Content entity I have one-to-many relation to Attachment entity like this:

/**
 * @var ArrayCollection|Attachment
 *
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Attachment", mappedBy="content")
 */
protected $attachments;

and of course on Attachment entity I have:

/**
 * @var Content
 *
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Content", inversedBy="attachments")
 */
private $content;

Some of STI entities extends Content entity but some of them extends abstract ListContent which is defined as mapped superclass and has some additional fields.

I want to be able to access attachments either from entities which extends Content and also entities which extends ListContent so I've put one-to-may association to Content entity since ListContent is extending it.

i was looking for solution but I can only find this one Doctrine2: OneToMany on mapped superclass and it is not appropriate for me since I don't want to define relationship on my ListContent.

Does anyone came across this issue? How did you resolve it?

Community
  • 1
  • 1
Cockootec
  • 536
  • 2
  • 7
  • 25
  • First thing I would try is changing the private $content to protected, second would be to include the joinColumn on the ManyToOne relationship like so: `@JoinColumn(name="customer_id", referencedColumnName="id")`. See more here [link](http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-joincolumn) – trevorengstrom Jul 09 '15 at 03:47
  • Unfortunately this didn't seem to work. Problem occurs on abstract class `ListContent` which extends `Content`. Field `attachments` is defined on `Content` class but the error is mentioning `ListContent`... Any idea? – Cockootec Jul 11 '15 at 21:45
  • @Cockootec Did you ever find a solution to this? – benface Jan 26 '20 at 16:09

0 Answers0