mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2042: Metadata association overriding : allow to override 'targetEntity' #2575
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
@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 @ocramius:
[~deatheriam] you can open a pull request with a test and suggested improvement for this at https://github.com/doctrine/doctrine2
@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.
@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.@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!
@vovkin commented on GitHub (Feb 10, 2022):
@fghamsary could you share the workaround?
@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):
@beberlei I think this issue could be considered as ready for closure, couldn't?
@fghamsary commented on GitHub (Jun 2, 2024):
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.