doctrine2 mapping overwrite inherited inversedBy field from MappedSuperclass

I had similar issue with single inheritance. I resolved this by defining same association in both entity classes (parent and inherited) but with different name. In your case you can try this:

    /** @ORM\Entity */
class FooLog extends BaseLog {
  /**
   * @ORM\ManyToOne(targetEntity="User", inversedBy="foologs")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
   * })
   */
   private $user;
}

and in class BarLog:

/** @ORM\Entity */
    class BarLog extends BaseLog {
      /**
       * @ORM\ManyToOne(targetEntity="User", inversedBy="barlogs")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
       * })
       */
       private $bar_user;
    }

Notice different name ($bar_user). You also have to define foologs and barlogs properties in user entity. This removes doctrine validation errors.


I have struggled with the same issue using Single Table Inheritance. As far as I can tell there isn't a solution to it. Even though inversedBy is considered compulsory, it seems you can get away with ignoring it. However, as the Doctrine docs suggest the performance deteriorates rapidly.

@AssociationOverride doesn't help, because you can't modify association definitions, only database column properties.

I've tried a number of options, none of which are satisfactory.

Update: I still haven't been able to find any solution to these sorts of errors when running app/console doctrine:schema:validate.

[Mapping]  FAIL - The entity-class 'Acme\AcmeBundle\Entity\CourseLocation' mapping is invalid:
* The field Acme\AcmeBundle\Entity\CourseLocation#facilitators is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Acme\AcmeBundle\Entity\CourseFacilitatorResponsibility#courseLocation does not contain the required 'inversedBy' attribute.

In this instance CourseFacilitatorResponsibility is a sub-class (with single table inheritance) of CourseResponsibility. CourseLocation refers to multiple CourseResponsibility entities. I think uni-directional associations is the only way around it.