Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1223

STI Inheritance Mapping Exception suggests to mark Entity abstract when initialization is not required, how to realize this?

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I have an abstract PHP class 'PartyAbstract' that uses Single Table Inheritance with a discriminator map to distinguish between a number of classes that extend the 'PartyAbstract' class. The 'PartyAbstract' class itself is not an entry in that discriminator map. Annotations are used to define the discriminator map.

       
      /**
      * @Entity
      * @Table(schema="public", name="party")
      * @InheritanceType("JOINED")
      * @DiscriminatorColumn(name="discriminator", type="integer")
      * @DiscriminatorMap({
      * "1" = "Project\Entity\Party\PartyType1",
      * "2" = "Project\Entity\Party\PartyType2",
      * "3" = "Project\Entity\Party\PartyType3"
      * })
      abstract class PartyAbstract{}
      

      As of version 2.1.0-rc1, the following exception is thrown:

       
      "Entity 'Project\Entity\PartyAbstract' has to be part of the descriminator map of 'Project\Entity\PartyAbstract' to be properly mapped in the inheritance hierachy. If you want to avoid instantiation of this type mark it abstract."
      

      My question is: how can I mark this Entity abstract? I DO want to be able to count the complete number of Parties, but instantiation of the PartyAbstract class is never required. The use of @MappedSuperclass is not allowed here, or together with the @Entity annotation...

      PS: also not that the message in the exception contains two typo's

      • 'descriminator' vs 'discriminator'
      • 'hierachy' vs 'hierarchy'

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This way:

        /**
        * @Entity
        * @Table(schema="public", name="party")
        * @InheritanceType("JOINED")
        * @DiscriminatorColumn(name="discriminator", type="integer")
        * @DiscriminatorMap({
        * "0" = "Project\Entity\Party\PartyAbstract",
        * "1" = "Project\Entity\Party\PartyType1",
        * "2" = "Project\Entity\Party\PartyType2",
        * "3" = "Project\Entity\Party\PartyType3"
        * })
        
        Show
        Benjamin Eberlei added a comment - This way: /** * @Entity * @Table(schema= " public " , name= "party" ) * @InheritanceType( "JOINED" ) * @DiscriminatorColumn(name= "discriminator" , type= "integer" ) * @DiscriminatorMap({ * "0" = "Project\Entity\Party\PartyAbstract" , * "1" = "Project\Entity\Party\PartyType1" , * "2" = "Project\Entity\Party\PartyType2" , * "3" = "Project\Entity\Party\PartyType3" * })
        Hide
        Menno Holtkamp added a comment -

        Aah, ok, that was the way I 'resolved' it, but the exception message confused me as it suggests that it requires a configuration setting to 'mark it abstract'. Maybe the following message can avoid this confusion:

        "Entity 'Project\Entity\PartyAbstract' has to be part of the discriminator map of 'Project\Entity\PartyAbstract' to be properly mapped in the inheritance hierarchy. If you want to avoid instantiation of this type, make it an abstract class"
        

        Thanks for the swift response!

        Show
        Menno Holtkamp added a comment - Aah, ok, that was the way I 'resolved' it, but the exception message confused me as it suggests that it requires a configuration setting to 'mark it abstract'. Maybe the following message can avoid this confusion: "Entity 'Project\Entity\PartyAbstract' has to be part of the discriminator map of 'Project\Entity\PartyAbstract' to be properly mapped in the inheritance hierarchy. If you want to avoid instantiation of this type, make it an abstract class" Thanks for the swift response!

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Menno Holtkamp
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: