Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2370

Subclass annotations not being read, unable to use OneToMany relation with single table inheritance

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3.2
    • Fix Version/s: None
    • Component/s: ORM
    • Environment:
      PHP 5.4.11

      Description

      Subclasses that override parent class properties and define relations will not work as expected, because AnnotationDriver/Reader will only use the parent class annotation (discarding whatever subclass defined).

      The following code will produce error:

      [Mapping]  FAIL - The entity-class 'Test\Office' mapping is invalid:
      * The mappings Test\Office#employees and Employee#office are incosistent with each other.
      

      Test code:

      <?php
      namespace Test;
       
      use Doctrine\ORM\Mapping as ORM;
       
      /**
       * @ORM\Entity
       */
      class Office 
      {
          /**
           * @ORM\OneToMany(targetEntity="Person", mappedBy="office")
           * @var Person[]|ArrayCollection
           */
          protected $people;
       
          /**
           * @ORM\OneToMany(targetEntity="Employee", mappedBy="office")
           * @var Employee[]|ArrayCollection
           */
          protected $employees;
       
      }
       
      /**
       * @ORM\Entity
       * @ORM\InheritanceType("SINGLE_TABLE")
       * @ORM\DiscriminatorColumn(name="type", type="string")
       * @ORM\DiscriminatorMap({"employee" = "Employee"})
       */
      class Person
      {
          /**
           * @ORM\ManyToOne(targetEntity="Office", inversedBy="people")
           * @var Office
           */
          protected $office;
      }
       
      /**
       * @ORM\Entity
       */
      class Employee extends Person
      {
          /**
           * @ORM\ManyToOne(targetEntity="Office", inversedBy="employees")
           * @var Office
           */
          protected $office;
      }
      

        Activity

        Arthur Bodera created issue -
        Hide
        Benjamin Eberlei added a comment -

        Overwriting assocations in this way is not supported.

        Show
        Benjamin Eberlei added a comment - Overwriting assocations in this way is not supported.
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]
        Hide
        Arthur Bodera added a comment -

        Ok, I get that it's not supported right now, but why did you mark it as resolved?

        Show
        Arthur Bodera added a comment - Ok, I get that it's not supported right now, but why did you mark it as resolved?

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2370, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Arthur Bodera
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: