DDC-378: Allow configuring of discriminatorMap from child classes #469

Closed
opened 2026-01-22 12:39:17 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 26, 2010).

Jira issue originally created by user @jwage:

/****
 * @Entity
 * @Table(name="sympal_content")
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"page" = "Page", "blog_post" = "BlogPost"})
 */
class Content
{

Would be nice if I could define this information from the child class so that I can drop in new tops without having to change the parent.

/****
 * @Entity
 * @Table(name="sympal*content_blog*post")
 */
class BlogPost extends Content
{
Originally created by @doctrinebot on GitHub (Feb 26, 2010). Jira issue originally created by user @jwage: ``` /**** * @Entity * @Table(name="sympal_content") * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"page" = "Page", "blog_post" = "BlogPost"}) */ class Content { ``` Would be nice if I could define this information from the child class so that I can drop in new tops without having to change the parent. ``` /**** * @Entity * @Table(name="sympal*content_blog*post") */ class BlogPost extends Content { ```
admin added the New Feature label 2026-01-22 12:39:18 +01:00
admin closed this issue 2026-01-22 12:39:18 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

@doctrinebot commented on GitHub (Feb 26, 2010): - is duplicated by [DDC-447: Allow setting of discriminatorValue from child classes](http://www.doctrine-project.org/jira/browse/DDC-447)
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by @beberlei:

This isn't really possible in a straightforward way, the Parent class has to know all the children to be able to transform a query like:

SELECT e FROM Super e

into their specific entities. These wouldn't be known however, since they are defined on a children.

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by @beberlei: This isn't really possible in a straightforward way, the Parent class has to know all the children to be able to transform a query like: ``` SELECT e FROM Super e ``` into their specific entities. These wouldn't be known however, since they are defined on a children.
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by @jwage:

Is it possible any other way to add to the discriminator map dynamically? Imagine I have a CMS with a base Node entity and a NodeType and I want to easily drop in new node types without having to modify the Node entity because the Node will not be something I own or have control over.

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by @jwage: Is it possible any other way to add to the discriminator map dynamically? Imagine I have a CMS with a base Node entity and a NodeType and I want to easily drop in new node types without having to modify the Node entity because the Node will not be something I own or have control over.
Author
Owner

@doctrinebot commented on GitHub (Feb 27, 2010):

Comment created by @jwage:

What about if I hook into the loadClassMetadata event in ClassMetadataFactory and add to the discriminator map?

@doctrinebot commented on GitHub (Feb 27, 2010): Comment created by @jwage: What about if I hook into the loadClassMetadata event in ClassMetadataFactory and add to the discriminator map?
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Comment created by romanb:

Jon, I think that last suggestion might work. The CMS would need to provide a way for the user to configure its own subclasses (say $cmsConfig->registerSubclass('MyCustomNode', 'Node'). The CMS itself can hook into loadClassMetadata and add the stuff from its config to the discriminator map.

@doctrinebot commented on GitHub (Mar 20, 2010): Comment created by romanb: Jon, I think that last suggestion might work. The CMS would need to provide a way for the user to configure its own subclasses (say $cmsConfig->registerSubclass('MyCustomNode', 'Node'). The CMS itself can hook into loadClassMetadata and add the stuff from its config to the discriminator map.
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Comment created by romanb:

Here an example how that might look like at the moment:

class MyLoadMetadataListener
{
    private $_cmsConfig;

    public function **construct($cmsConfig)
    {
         $this->_cmsConfig = $cmsConfig;
    }

    public function loadClassMetadata($class)
    {
        // Dynamically add new subclasses to the discriminator map of the Node class.
        if ($class->name == 'Node') {
             foreach ($this->_cmsConfig->getCustomNodes() as $discrValue => $className) {
                 $class->discriminatorMap[$discrValue] = $className;
                 $class->subClasses[] = $className; // eventually check for duplicates
             }
        }
    }
}

$cmsConfig->registerCustomNode('custNode' => 'My\Custom\Node');

...
@doctrinebot commented on GitHub (Mar 20, 2010): Comment created by romanb: Here an example how that might look like at the moment: ``` class MyLoadMetadataListener { private $_cmsConfig; public function **construct($cmsConfig) { $this->_cmsConfig = $cmsConfig; } public function loadClassMetadata($class) { // Dynamically add new subclasses to the discriminator map of the Node class. if ($class->name == 'Node') { foreach ($this->_cmsConfig->getCustomNodes() as $discrValue => $className) { $class->discriminatorMap[$discrValue] = $className; $class->subClasses[] = $className; // eventually check for duplicates } } } } $cmsConfig->registerCustomNode('custNode' => 'My\Custom\Node'); ... ```
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Comment created by @jwage:

Sweet, this solution works for me. As long as we can add in new children in some way without having to modify the parents mapping information directly.

@doctrinebot commented on GitHub (Mar 20, 2010): Comment created by @jwage: Sweet, this solution works for me. As long as we can add in new children in some way without having to modify the parents mapping information directly.
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Mar 20, 2010): Issue was closed with resolution "Can't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#469