DDC-3090: Cannot use single table inheritance in entities deriving from classes using class table inheritance #3835

Closed
opened 2026-01-22 14:28:52 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 17, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user sparrowek:

I have the following classes:

/****
 * @ORM\Table(name="diet_entries")
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({"recipe" = "Recipe", "ingredient" = "Ingredient" })
 */
abstract class DietEntry {}
/****
 * @ORM\Table(name="recipes")
 */
class Recipe extends DietEntry {}
/****
 * @ORM\Table(name="ingredients")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({ "ingredient" = "Ingredient", "supplement" = "Supplement" })
 */
class Ingredient extends DietEntry {}
/****
 * @ORM\Entity
 */
class Supplement extends Ingredient {}

and these tables: diet_entries, recipes, ingredients.

The idea was not to create the table for supplements since a supplement needs no extra attributes other then those derived from an ingredient, otherwise I would have added Supplement to discriminator map of DietEntry and provided a table for it which is mandatory in JOINED inheritance.
But the problem now is that when a query is build it looks like this:

An exception occurred while executing
SELECT i0*.id AS id0, i0_.name AS name1, i0_.energy AS energy2, d1_.name AS name3, d2_.name AS name4 FROM ingredients i0_ INNER JOIN diet_databases d1_ ON d3_.database_id = d1_.id LEFT JOIN dictionary d2_ ON i0_.group_id = d2_.id WHERE i0*.discriminator IN ('ingredient', 'supplement')

{quote}SQLSTATE[42S22]: Column not found: 1054 Unknown column 'i0_.name' in 'field list{quote}

The query for Ingredient is missing a join with the diet_entries table from which the ingredient derives. ORM only sees entities/tables down the inheritance path from the Ingredient class but not up from Ingredient to DietEntry

Originally created by @doctrinebot on GitHub (Apr 17, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user sparrowek: I have the following classes: ``` /**** * @ORM\Table(name="diet_entries") * @ORM\Entity * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discriminator", type="string") * @ORM\DiscriminatorMap({"recipe" = "Recipe", "ingredient" = "Ingredient" }) */ abstract class DietEntry {} ``` ``` /**** * @ORM\Table(name="recipes") */ class Recipe extends DietEntry {} ``` ``` /**** * @ORM\Table(name="ingredients") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="discriminator", type="string") * @ORM\DiscriminatorMap({ "ingredient" = "Ingredient", "supplement" = "Supplement" }) */ class Ingredient extends DietEntry {} ``` ``` /**** * @ORM\Entity */ class Supplement extends Ingredient {} ``` and these tables: `diet_entries`, `recipes`, `ingredients`. The idea was not to create the table for supplements since a supplement needs no extra attributes other then those derived from an ingredient, otherwise I would have added Supplement to discriminator map of DietEntry and provided a table for it which is mandatory in JOINED inheritance. But the problem now is that when a query is build it looks like this: An exception occurred while executing `SELECT i0*.id AS id0, i0_.name AS name1, i0_.energy AS energy2, d1_.name AS name3, d2_.name AS name4 FROM ingredients i0_ INNER JOIN diet_databases d1_ ON d3_.database_id = d1_.id LEFT JOIN dictionary d2_ ON i0_.group_id = d2_.id WHERE i0*.discriminator IN ('ingredient', 'supplement')` {quote}SQLSTATE[42S22]: Column not found: 1054 Unknown column 'i0_.name' in 'field list{quote} The query for Ingredient is missing a join with the diet_entries table from which the ingredient derives. ORM only sees entities/tables down the inheritance path from the Ingredient class but not up from Ingredient to DietEntry
admin added the Bug label 2026-01-22 14:28:52 +01:00
admin closed this issue 2026-01-22 14:28:53 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 17, 2014):

Comment created by @ocramius:

Duplicate of DDC-138

@doctrinebot commented on GitHub (Apr 17, 2014): Comment created by @ocramius: Duplicate of [DDC-138](http://www.doctrine-project.org/jira/browse/DDC-138)
Author
Owner

@doctrinebot commented on GitHub (Apr 17, 2014):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Apr 17, 2014): Issue was closed with resolution "Duplicate"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3835