doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.92k stars 2.51k forks source link

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

Open doctrinebot opened 12 years ago

doctrinebot commented 12 years ago

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 10 years ago

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 10 years ago

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 4 years ago

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 2 years ago

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

fghamsary commented 2 years ago

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 2 years ago

@fghamsary could you share the workaround?

Xavi-Conkau commented 3 months ago

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 3 months ago

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

fghamsary commented 3 months ago

@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.