[PR #221] [CLOSED] [Inheritance] Joined: Default discriminator map #7877

Open
opened 2026-01-22 15:57:20 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/221
Author: @comfortablynumb
Created: 12/16/2011
Status: Closed

Base: masterHead: default-discriminator-map


📝 Commits (10+)

  • d7042ab Merge branch 'master', remote branch 'upstream/master'
  • bf9024b Merge remote branch 'upstream/master'
  • 6d5f15e Merge remote branch 'upstream/master'
  • e61d959 [Inheritance] Joined type: Added default discriminator map (only annotations yet)
  • 6923fe9 Some minor CS fixes.
  • 842f87c [Inheritance] Joined: Changed implementation of the default discriminator map calculation
  • b4eb7a5 Optimized a little bit the generation of the default discriminator map
  • 80d088f Fixed test and other minor issues
  • a76b0a5 Some refactor in ClassMetadataFactory
  • 2a54975 Added more tests

📊 Changes

5 files changed (+165 additions, -4 deletions)

View changed files

📝 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php (+90 -4)
tests/Doctrine/Tests/Models/JoinedInheritanceType/AnotherChildClass.php (+10 -0)
tests/Doctrine/Tests/Models/JoinedInheritanceType/ChildClass.php (+10 -0)
tests/Doctrine/Tests/Models/JoinedInheritanceType/RootClass.php (+16 -0)
📝 tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php (+39 -0)

📄 Description

Hi all,

I know this topic was discussed a lot of times, but I wanted to give it a try anyway.

I want the discriminator map to be configured dynamically by doctrine instead of having to manually configure it myself. So I've digged into the code and the only place I've found (yet) to put the necessary code to make this happen is in the Drivers, just when they're loading the mapping information. So far, I've put a very simple piece of code in the AnnotationDriver to give it a try and I wrote a test for it. But before going on I wanted to ask you if it looks ok for you.

I've tested it in an application I'm working on and, so far, it works.

So, in a brief, what this does is, if you have a class which is the root of a class table inheritance tree (JOINED type), you can let doctrine configure the DiscriminatorMap for you, filling it with all the subclasses of the root class. If, for some reason, the user needs to configure it by himself, then he can do it. If the DiscriminatorMap is set, Doctrine doesn't generate it.

I think this is useful. It's error prone to configure it manually every time a new class is added to the inheritance tree. And this is better in cases where you can't know which entities are present and which aren't (for example, think about pluggable modules in a modular application). There's a way to do it (although I didn't try it. Just read about it), but this is simpler and works out of the box.

Two things come to mind though:

  1. Is there any special case this would cause problems that I don't know of?
  2. If not then, Is there a better place to put this code so I don't have to implement it in all drivers? I've been looking at the ClassMetadataFactory class but I didn't find a place to put this code because it seems it's too late to calculate the discriminator map at the time this class is used. So, in case there is no other place, where should I refactor the logic? It feels uncomfortable to create a class just to put this simple logic on, but as drivers don't inherit from any class, I don't see another option.

I'll wait for your comments to continue with this.

Thanks!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/221 **Author:** [@comfortablynumb](https://github.com/comfortablynumb) **Created:** 12/16/2011 **Status:** ❌ Closed **Base:** `master` ← **Head:** `default-discriminator-map` --- ### 📝 Commits (10+) - [`d7042ab`](https://github.com/doctrine/orm/commit/d7042ab828c487420371a6ac12e32359e9e204fa) Merge branch 'master', remote branch 'upstream/master' - [`bf9024b`](https://github.com/doctrine/orm/commit/bf9024b622653efa2b3ac4cb0dd41c2a6689c8f7) Merge remote branch 'upstream/master' - [`6d5f15e`](https://github.com/doctrine/orm/commit/6d5f15e70886ec42db6b0f2e9b6a49310c584a0b) Merge remote branch 'upstream/master' - [`e61d959`](https://github.com/doctrine/orm/commit/e61d959fc9158b33d004ac00854e2906b0b67100) [Inheritance] Joined type: Added default discriminator map (only annotations yet) - [`6923fe9`](https://github.com/doctrine/orm/commit/6923fe9ad7a0c698ce3518f97d3ae87e4e2c777f) Some minor CS fixes. - [`842f87c`](https://github.com/doctrine/orm/commit/842f87caab67917268e265877bb6c2b2ebc59fd5) [Inheritance] Joined: Changed implementation of the default discriminator map calculation - [`b4eb7a5`](https://github.com/doctrine/orm/commit/b4eb7a5cd8ba1356522a5b7ea58eb5e62067b83c) Optimized a little bit the generation of the default discriminator map - [`80d088f`](https://github.com/doctrine/orm/commit/80d088f4676d417ecb3e85b3ee4c25beea6af2d5) Fixed test and other minor issues - [`a76b0a5`](https://github.com/doctrine/orm/commit/a76b0a533b6b3c316df138c27eff3f77344aa07e) Some refactor in ClassMetadataFactory - [`2a54975`](https://github.com/doctrine/orm/commit/2a5497549f56c7ef1e52dbf2a0833c8388473928) Added more tests ### 📊 Changes **5 files changed** (+165 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php` (+90 -4) ➕ `tests/Doctrine/Tests/Models/JoinedInheritanceType/AnotherChildClass.php` (+10 -0) ➕ `tests/Doctrine/Tests/Models/JoinedInheritanceType/ChildClass.php` (+10 -0) ➕ `tests/Doctrine/Tests/Models/JoinedInheritanceType/RootClass.php` (+16 -0) 📝 `tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php` (+39 -0) </details> ### 📄 Description Hi all, I know this topic was discussed a lot of times, but I wanted to give it a try anyway. I want the discriminator map to be configured dynamically by doctrine instead of having to manually configure it myself. So I've digged into the code and the only place I've found (yet) to put the necessary code to make this happen is in the Drivers, just when they're loading the mapping information. So far, I've put a very simple piece of code in the AnnotationDriver to give it a try and I wrote a test for it. But before going on I wanted to ask you if it looks ok for you. I've tested it in an application I'm working on and, so far, it works. So, in a brief, what this does is, if you have a class which is the root of a class table inheritance tree (JOINED type), you can let doctrine configure the DiscriminatorMap for you, filling it with all the subclasses of the root class. If, for some reason, the user needs to configure it by himself, then he can do it. If the DiscriminatorMap is set, Doctrine doesn't generate it. I think this is useful. It's error prone to configure it manually every time a new class is added to the inheritance tree. And this is better in cases where you can't know which entities are present and which aren't (for example, think about pluggable modules in a modular application). There's a way to do it (although I didn't try it. Just read about it), but this is simpler and works out of the box. Two things come to mind though: 1) Is there any special case this would cause problems that I don't know of? 2) If not then, Is there a better place to put this code so I don't have to implement it in all drivers? I've been looking at the ClassMetadataFactory class but I didn't find a place to put this code because it seems it's too late to calculate the discriminator map at the time this class is used. So, in case there is no other place, where should I refactor the logic? It feels uncomfortable to create a class just to put this simple logic on, but as drivers don't inherit from any class, I don't see another option. I'll wait for your comments to continue with this. Thanks! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 15:57:20 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7877