DDC-3122: Querying entities with ResolveTargetEntity #3875

Open
opened 2026-01-22 14:30:09 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (May 14, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user heo:

Hello

The problem refers to a following situation:
You have 2 classes that use a quite simple inheritance and an interface:

interface CInterface { /** ... **/ }
class AClass implements CInterface { /** ... **/ }
class BClass extends class AClass { /** ... **/ }

When we configure the ResolveTargetEntityListener the following way:

array(
  'CInterface' => 'BClass'
)

when using the entity manager to find an entity:

$entityManager->find('BClass', $id);

we'll get a following Doctrine\DBAL\DBALException:
{quote}An exception occurred while executing 'SELECT t1.id AS id2 FROM bclass_table_name t1 WHERE t0.id = ?' with params [1]:{quote}

{quote}SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.id' in 'where clause'{quote}

As you can see the column names are generated properly but the WHERE clause has an invalid refference to t0 table (should be t1).

Similar problem:

http://stackoverflow.com/questions/17588682/doctrine-inheritance-replacement

Originally created by @doctrinebot on GitHub (May 14, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user heo: Hello The problem refers to a following situation: You have 2 classes that use a quite simple inheritance and an interface: ``` interface CInterface { /** ... **/ } class AClass implements CInterface { /** ... **/ } class BClass extends class AClass { /** ... **/ } ``` When we configure the `ResolveTargetEntityListener` the following way: ``` array( 'CInterface' => 'BClass' ) ``` when using the entity manager to find an entity: ``` $entityManager->find('BClass', $id); ``` we'll get a following `Doctrine\DBAL\DBALException`: {quote}An exception occurred while executing 'SELECT t1.id AS id2 FROM bclass_table_name t1 WHERE t0.id = ?' with params [1]:{quote} {quote}SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.id' in 'where clause'{quote} As you can see the column names are generated properly but the WHERE clause has an invalid refference to t0 table (should be t1). Similar problem: http://stackoverflow.com/questions/17588682/doctrine-inheritance-replacement
admin added the Bug label 2026-01-22 14:30:09 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 14, 2014):

Comment created by @ocramius:

Is AClass a mapped superclass or the root of the inheritance?

@doctrinebot commented on GitHub (May 14, 2014): Comment created by @ocramius: Is `AClass` a mapped superclass or the root of the inheritance?
Author
Owner

@doctrinebot commented on GitHub (May 15, 2014):

Comment created by heo:

AClass is the root of the inheritance. I would like to add that the only problem is the "find" method. Database relations are created properly (with the SchemaTool), all keys refer to proper columns.

@doctrinebot commented on GitHub (May 15, 2014): Comment created by heo: AClass is the root of the inheritance. I would like to add that the only problem is the "find" method. Database relations are created properly (with the SchemaTool), all keys refer to proper columns.
Author
Owner

@doctrinebot commented on GitHub (May 15, 2014):

Comment created by @ocramius:

[~heo] can you abstract a test case for this?

@doctrinebot commented on GitHub (May 15, 2014): Comment created by @ocramius: [~heo] can you abstract a test case for this?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3875