Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-3090

Cannot use single table inheritance in entities deriving from classes using class table inheritance


    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:


      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')

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

      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


        ocramius Marco Pivetta added a comment -

        Duplicate of DDC-138

        ocramius Marco Pivetta added a comment - Duplicate of DDC-138


          • Assignee:
            ocramius Marco Pivetta
            sparrowek Przemyslaw Wrobel
          • Votes:
            0 Vote for this issue
            2 Start watching this issue


            • Created: