Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-447

Allow setting of discriminatorValue from child classes

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Can't Fix
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: None
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None

      Description

      What do you think of something like this? It needs to be implemented for the other drivers, but before I implement the rest of it I want to make sure you are okay with it. With this patch it makes it easier to drop in new child classes without having to modify the parent class.

      The use case is in a content management framework where we provide a base Node entity and the developers can extend that Node. In this scenario they won't really be able to modify the mapping information for that class included in the framework. With this patch they can drop in new child classes and specify the discriminatorValue there and it is added to the topmost parent class in the ClassMetadataFactory

        Issue Links

          Activity

          Hide
          Jonathan H. Wage added a comment -

          Just a not here, this allows this syntax in your annotations:

          /** @Entity(discriminatorValue="auction") @Table(name="company_auctions") */
          class CompanyAuction extends CompanyEvent {
          

          Instead of having to specify it in the top most parent class.

          YAML:

          CompanyAuction:
            discriminiatorValue: auction
          

          XML:

              <entity name="CompanyAuction" discriminator-value="auction">
          
          Show
          Jonathan H. Wage added a comment - Just a not here, this allows this syntax in your annotations: /** @Entity(discriminatorValue= "auction" ) @Table(name= "company_auctions" ) */ class CompanyAuction extends CompanyEvent { Instead of having to specify it in the top most parent class. YAML: CompanyAuction: discriminiatorValue: auction XML: <entity name= "CompanyAuction" discriminator-value= "auction" >
          Hide
          Roman S. Borschel added a comment - - edited

          I dont think that will work because the discriminator map also indirectly declares the subclasses. For example if you only load the parent class, CompanyEvent, the subclasses will not be set properly and this will cause all kinds of issues. Even if we had a @SubClasses annotation still, it would be the same issue since specifying all the subclasses in the parent class is exactly what you want to avoid.

          Thus this feature is not possible due to the way the metadata is loaded. It would be possible if we always load the whole hierarchy (or at least all subclasses which means the whole hierarchy if the requested class is the root class) as soon as the metadata of 1 class of the hierarchy is required but this would be very inefficient.

          Show
          Roman S. Borschel added a comment - - edited I dont think that will work because the discriminator map also indirectly declares the subclasses. For example if you only load the parent class, CompanyEvent, the subclasses will not be set properly and this will cause all kinds of issues. Even if we had a @SubClasses annotation still, it would be the same issue since specifying all the subclasses in the parent class is exactly what you want to avoid. Thus this feature is not possible due to the way the metadata is loaded. It would be possible if we always load the whole hierarchy (or at least all subclasses which means the whole hierarchy if the requested class is the root class) as soon as the metadata of 1 class of the hierarchy is required but this would be very inefficient.
          Hide
          Roman S. Borschel added a comment -

          Thinking further ... even if we would want to load the metadata of all subclasses ... how do we know what are the subclasses? Either I'm missing something or this is not doable at all.

          It comes down to this question: When you do: $em->getClassMetadata('SomeClassWithChildren'), we need to know all (mapped) subclasses of this class. How is that possible without having them specified on this class (ie through the discriminator map) ?

          Show
          Roman S. Borschel added a comment - Thinking further ... even if we would want to load the metadata of all subclasses ... how do we know what are the subclasses? Either I'm missing something or this is not doable at all. It comes down to this question: When you do: $em->getClassMetadata('SomeClassWithChildren'), we need to know all (mapped) subclasses of this class. How is that possible without having them specified on this class (ie through the discriminator map) ?
          Hide
          Roman S. Borschel added a comment -

          See also my last comment on Jonathans last suggestion on DDC-378 .

          Show
          Roman S. Borschel added a comment - See also my last comment on Jonathans last suggestion on DDC-378 .
          Hide
          Jonathan H. Wage added a comment -

          You are right, this approach cannot ever work as far as I can see now. The other approach using the events works and would work for me.

          Show
          Jonathan H. Wage added a comment - You are right, this approach cannot ever work as far as I can see now. The other approach using the events works and would work for me.
          Hide
          Miha Vrhovnik added a comment -
          Show
          Miha Vrhovnik added a comment - @Roman: So this doesn't work as it is supposed? http://thoughtsofthree.com/2011/04/defining-discriminator-maps-at-child-level-in-doctrine-2-0/

            People

            • Assignee:
              Roman S. Borschel
              Reporter:
              Jonathan H. Wage
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: