orm icon indicating copy to clipboard operation
orm copied to clipboard

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

Open doctrinebot opened this issue 13 years ago • 9 comments

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 avatar Sep 26 '12 08:09 doctrinebot

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 avatar Mar 31 '14 22:03 doctrinebot

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 avatar Mar 31 '14 22:03 doctrinebot

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 avatar Jul 28 '20 09:07 fghamsary

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

vovkin avatar Feb 10 '22 12:02 vovkin

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 avatar Feb 10 '22 14:02 fghamsary

@fghamsary could you share the workaround?

vovkin avatar Feb 10 '22 14:02 vovkin

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 avatar Jun 02 '24 10:06 Xavi-Conkau

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

Xavi-Conkau avatar Jun 02 '24 10:06 Xavi-Conkau

@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 avatar Jun 02 '24 10:06 fghamsary