Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving target entities from abstract class seems to not working as expected #7670

Open
emulienfou opened this issue Apr 1, 2019 · 5 comments
Assignees

Comments

@emulienfou
Copy link

Hello, according to the How to Define Relationships with Abstract Classes and Interfaces, I should be able to use the ResolveTargetEntityListener to resolve an abstract class to a specific entity.

However, this "feature" seems to not working properly.

1. Using an interface

Here is the PHP code used to resolve the interface to the entity class;

$registry
    ->getManager()
    ->getMetadataFactory()
    ->getMetadataFor(RedirectRouteInterface::class)
    ->getName();

$registry is an instance of \Doctrine\Common\Persistence\ManagerRegistry

When configuring doctrine using an interface like:

doctrine:
    orm:
        resolve_target_entities:
            Symfony\Cmf\Component\Routing\RedirectRouteInterface: App\Entity\RedirectRoute

everything is working perfectly and the name is equals to App\Entity\RedirectRoute

2. Using an abstract class

Now when I'm trying to resolve an entity from an abstract class, the resolver seems to not working properly.
Here is the PHP code used to resolve the abstract class to the entity class:

$registry
    ->getManager()
    ->getMetadataFactory()
    ->getMetadataFor(AbstractRedirectRoute::class)
    ->getName();

$registry is an instance of \Doctrine\Common\Persistence\ManagerRegistry

When configuring doctrine using an abstract class like:

doctrine:
    orm:
        resolve_target_entities:
            App\Model\AbstractRedirectRoute: App\Entity\RedirectRoute

In that case, the resolver is returning the abstract class FQCN: App\Model\AbstractRedirectRoute.

Weird thing is, to be able to resolve the abstract class I need to make the call to getAllMetadata() method like:

$registry
    ->getManager()
    ->getMetadataFactory()
    ->getAllMetadata();
$registry
    ->getManager()
    ->getMetadataFactory()
    ->getMetadataFor(AbstractRedirectRoute::class)
    ->getName();

In that case, the entity is resolved correctly!


Is this an issue or more a miss-configuration on my side?

@alcaeus alcaeus transferred this issue from doctrine/DoctrineBundle Apr 4, 2019
@alcaeus
Copy link
Member

alcaeus commented Apr 4, 2019

@emulienfou I've moved the issue to the ORM repository as the bundle only configures the class contained here with the data you pass in the configuration. I would assume there's an issue with the logic here.

@Ocramius
Copy link
Member

Ocramius commented Apr 4, 2019

Can this be reproduced solely with the ClassMetadataFactory?

@teohhanhui
Copy link
Contributor

teohhanhui commented May 28, 2019

Could be the same as: doctrine/common#369 (doctrine/persistence#27)

@hxss
Copy link

hxss commented Apr 4, 2021

@mpdude
Copy link
Contributor

mpdude commented Jan 16, 2023

If you still can/know how to reproduce this issue, could you check if #10411 helps?

Sorry, it’s not related as I initially thought

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants