DDC-258: DiscriminatorMap Ordering Affects Mapping #318

Open
opened 2026-01-22 12:34:33 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 15, 2010).

Jira issue originally created by user mridgway:

In an inheritance tree, I have a super class with three subclasses. Two of the subclasses have a 'title' and 'description' field, but one of those has an extra field. The third class doesn't share any properties, but demonstrates the reasoning for not having 'title' and 'description' in the super class.

So, the problem I'm getting is that only one of these classes can work at a time, depending on which is first in the DiscriminatorMap. The SQL query performs left joins on all of the tables and uses aliases to keep the common fields separated. The mapper doesn't seem to be using the aliases when it maps the properties to the object. It seems override properties even if they aren't in the correct table.

Example:

/****
 * @Entity
 * @Table(name="Content")
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"class1" = "Class1", "class2" = "Class2", "class3"="Class3"})
 */
abstract class Super
{
    /****
     * @Id @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
    */
    protected $id;
}

/****
 * @Entity
 */
class Class1 extends Super
{
    /****
     * @Column(name="title", type="string", length="150")
     */
    protected $title;

    /****
     * @Column(name="content", type="string", length="500")
     */
    protected $description;
}

/****
 * @Entity
 */
class Class2 extends Super
{
    /****
     * @Column(name="title", type="string", length="150")
     */
    protected $title;

    /****
     * @Column(name="content", type="string", length="500")
     */
    protected $description;

    /****
     * @Column(name="text", type="text")
     */
    protected $text;
}

/****
 * An extra class to demonstrate why title and description aren't in Super
 *
 * @Entity
 */
class Class3 extends Super
{
    /****
     * @Column(name="title", type="string", length="150")
     */
    protected $apples;

    /****
     * @Column(name="content", type="string", length="500")
     */
    protected $bananas;
}

The select for a Super of id 2 uses the following query (or similar):
noneSELECT t0.id, t0.type, t1.title, t1.description, t2.title, t2.description, t2.text, t3.apples, t3.bananas FROM Super t0 LEFT JOIN Class1 t1 ON t0.id = t1.id LEFT JOIN Class2 t2 ON t0.id = t2.id LEFT JOIN Class3 t3 ON t0.id = t3.id WHERE t0.id = 2;

Now, if the DiscriminatorMap is reordered, the joins change order as well, which seems to affect which fields actually get mapped to the object.

Originally created by @doctrinebot on GitHub (Jan 15, 2010). Jira issue originally created by user mridgway: In an inheritance tree, I have a super class with three subclasses. Two of the subclasses have a 'title' and 'description' field, but one of those has an extra field. The third class doesn't share any properties, but demonstrates the reasoning for not having 'title' and 'description' in the super class. So, the problem I'm getting is that only one of these classes can work at a time, depending on which is first in the DiscriminatorMap. The SQL query performs left joins on all of the tables and uses aliases to keep the common fields separated. The mapper doesn't seem to be using the aliases when it maps the properties to the object. It seems override properties even if they aren't in the correct table. Example: ``` none /**** * @Entity * @Table(name="Content") * @InheritanceType("JOINED") * @DiscriminatorColumn(name="type", type="string") * @DiscriminatorMap({"class1" = "Class1", "class2" = "Class2", "class3"="Class3"}) */ abstract class Super { /**** * @Id @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; } /**** * @Entity */ class Class1 extends Super { /**** * @Column(name="title", type="string", length="150") */ protected $title; /**** * @Column(name="content", type="string", length="500") */ protected $description; } /**** * @Entity */ class Class2 extends Super { /**** * @Column(name="title", type="string", length="150") */ protected $title; /**** * @Column(name="content", type="string", length="500") */ protected $description; /**** * @Column(name="text", type="text") */ protected $text; } /**** * An extra class to demonstrate why title and description aren't in Super * * @Entity */ class Class3 extends Super { /**** * @Column(name="title", type="string", length="150") */ protected $apples; /**** * @Column(name="content", type="string", length="500") */ protected $bananas; } ``` The select for a Super of id 2 uses the following query (or similar): `noneSELECT t0.id, t0.type, t1.title, t1.description, t2.title, t2.description, t2.text, t3.apples, t3.bananas FROM Super t0 LEFT JOIN Class1 t1 ON t0.id = t1.id LEFT JOIN Class2 t2 ON t0.id = t2.id LEFT JOIN Class3 t3 ON t0.id = t3.id WHERE t0.id = 2;` Now, if the DiscriminatorMap is reordered, the joins change order as well, which seems to affect which fields actually get mapped to the object.
admin added the Bug label 2026-01-22 12:34:33 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#318