Skip to content

Loading…

DDC-447: Allow setting of discriminatorValue from child classes #4948

Closed
doctrinebot opened this Issue · 10 comments

1 participant

@doctrinebot

Jira issue originally created by user @jwage:

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

@doctrinebot

Comment created by @jwage:

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">
@doctrinebot

Comment created by romanb:

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.

@doctrinebot

Comment created by romanb:

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

@doctrinebot

Comment created by romanb:

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

@doctrinebot

Comment created by @jwage:

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.

@doctrinebot

Issue was closed with resolution "Can't Fix"

@doctrinebot

Comment created by zquintana:

I'd like to see this too, so +1. Not sure what the complexities may be, but would be useful for simple extension of existing entities without having to change core objects. That is a big deal on large projects in my experience.

@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.