DDC-2370: Subclass annotations not being read, unable to use OneToMany relation with single table inheritance #2977

Closed
opened 2026-01-22 14:08:53 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 26, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user thinkscape:

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;
}
Originally created by @doctrinebot on GitHub (Mar 26, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user thinkscape: 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; } ```
admin added the Bug label 2026-01-22 14:08:53 +01:00
admin closed this issue 2026-01-22 14:08:54 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 1, 2013):

Comment created by @beberlei:

Overwriting assocations in this way is not supported.

@doctrinebot commented on GitHub (May 1, 2013): Comment created by @beberlei: Overwriting assocations in this way is not supported.
Author
Owner

@doctrinebot commented on GitHub (May 1, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (May 1, 2013): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (May 1, 2013):

Comment created by thinkscape:

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

@doctrinebot commented on GitHub (May 1, 2013): Comment created by thinkscape: Ok, I get that it's not supported right now, but why did you mark it as resolved?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2977