DDC-2042: Metadata association overriding : allow to override 'targetEntity' #2575

Open
opened 2026-01-22 13:57:22 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 26, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user cro:

While associating object to an descriminated table I wasn't enable to fix the entityTarget (only one can be set in entity annotation).

It could be resolve by adding the possibility to override 'targetEntity' value in Doctrine\ORM\Mapping\ClassMetadataInfo::ClassMetadataInfo().

Such as :
{quote}
if (isset($overrideMapping['targetEntity'])) {
$mapping['targetEntity'] = $overrideMapping['targetEntity'];
}
{quote}

That would need to add a control on the new targetEntity in Doctrine\ORM\Mapping\ClassMetadataInfo::_validateAndCompleteAssociationMapping().

Such as :
{quote}
if ( ! ClassLoader::classExists($mapping['targetEntity']) ) {
throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']);
}
{quote}

cro.

Originally created by @doctrinebot on GitHub (Sep 26, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user cro: While associating object to an descriminated table I wasn't enable to fix the entityTarget (only one can be set in entity annotation). It could be resolve by adding the possibility to override 'targetEntity' value in Doctrine\ORM\Mapping\ClassMetadataInfo::ClassMetadataInfo(). Such as : {quote} if (isset($overrideMapping['targetEntity'])) { $mapping['targetEntity'] = $overrideMapping['targetEntity']; } {quote} That would need to add a control on the new targetEntity in Doctrine\ORM\Mapping\ClassMetadataInfo::_validateAndCompleteAssociationMapping(). Such as : {quote} if ( ! ClassLoader::classExists($mapping['targetEntity']) ) { throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']); } {quote} cro.
admin added the Improvement label 2026-01-22 13:57:22 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 31, 2014):

Comment created by deatheriam:

We need this feature too. Why is this ticket in a limbo? Someone please add a comment whether this will be fixed.

@doctrinebot commented on GitHub (Mar 31, 2014): Comment created by deatheriam: We need this feature too. Why is this ticket in a limbo? Someone please add a comment whether this will be fixed.
Author
Owner

@doctrinebot commented on GitHub (Mar 31, 2014):

Comment created by @ocramius:

[~deatheriam] you can open a pull request with a test and suggested improvement for this at https://github.com/doctrine/doctrine2

@doctrinebot commented on GitHub (Mar 31, 2014): Comment created by @ocramius: [~deatheriam] you can open a pull request with a test and suggested improvement for this at https://github.com/doctrine/doctrine2
Author
Owner

@fghamsary commented on GitHub (Jul 28, 2020):

It seems that nobody want to add this, but it's really something that is missing.
I'm going to do a pull request for this, if it would be possible to be added to latest version it would be a great help.

@fghamsary commented on GitHub (Jul 28, 2020): It seems that nobody want to add this, but it's really something that is missing. I'm going to do a pull request for this, if it would be possible to be added to latest version it would be a great help.
Author
Owner

@vovkin commented on GitHub (Feb 10, 2022):

@fghamsary did you give it a try? It seems that it's still not possible to override targetEntity.

@vovkin commented on GitHub (Feb 10, 2022): @fghamsary did you give it a try? It seems that it's still not possible to override `targetEntity`.
Author
Owner

@fghamsary commented on GitHub (Feb 10, 2022):

I can confirm that it's not possible, and I found a work around by not using targetEntity, because it was not working as it should!

@fghamsary commented on GitHub (Feb 10, 2022): I can confirm that it's not possible, and I found a work around by not using targetEntity, because it was not working as it should!
Author
Owner

@vovkin commented on GitHub (Feb 10, 2022):

@fghamsary could you share the workaround?

@vovkin commented on GitHub (Feb 10, 2022): @fghamsary could you share the workaround?
Author
Owner

@Xavi-Conkau commented on GitHub (Jun 2, 2024):

I think him refers to https://www.doctrine-project.org/projects/doctrine-orm/en/3.2/cookbook/resolve-target-entity-listener.html
Please @fghamsary ask me if you need a wider answer with samples.

@Xavi-Conkau commented on GitHub (Jun 2, 2024): I think him refers to https://www.doctrine-project.org/projects/doctrine-orm/en/3.2/cookbook/resolve-target-entity-listener.html Please @fghamsary ask me if you need a wider answer with samples.
Author
Owner

@Xavi-Conkau commented on GitHub (Jun 2, 2024):

@beberlei I think this issue could be considered as ready for closure, couldn't?

@Xavi-Conkau commented on GitHub (Jun 2, 2024): @beberlei I think this issue could be considered as ready for closure, couldn't?
Author
Owner

@fghamsary commented on GitHub (Jun 2, 2024):

@fghamsary could you share the workaround?

To be honest, I don't remember what I did to resolve the problem, I think I didn't specified the targetEntity on the abstract class, and duplicated the field two times on each children.
But it has been a while, so I really don't know what I did.
I'll try to find on our code base the workaround that I used, and if I find it, I'll let you know.

@fghamsary commented on GitHub (Jun 2, 2024): > @fghamsary could you share the workaround? To be honest, I don't remember what I did to resolve the problem, I think I didn't specified the targetEntity on the abstract class, and duplicated the field two times on each children. But it has been a while, so I really don't know what I did. I'll try to find on our code base the workaround that I used, and if I find it, I'll let you know.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2575