DDC-1390: Lazy loading does not work for the relationships of an entity instance, whose class inherits from another entity class #1741

Open
opened 2026-01-22 13:23:53 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 22, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user dalvarez:

Lazy loading does not work for the relationships of an instance of an entity, whose class inherits from another entity class.

Assume there are two entity classes, A and B, where A inherits from B.

Now let $a be an instance of A, e. g. the result of "SELECT a FROM \A WHERE a.id = 1".

Outputting $a will confirm it is a valid instance of a proxy object inheriting from A.

Assume that the database row corresponding to $a contains a non-null foreign key that actually links to an existing row in another table, corresponding to another entity instance of a different class.

Now, $a->someRelationship will always returns null in this scenario. I assume this is unintended behaviour, because clearly, the other entity should be lazily loaded on accessing it, and there is a value in the database.

The fetch annotation attribute on that relationship has not been explicitly set, so I assume it is set to the default value, which, according to the docs, should be "lazy".

The loading only fails when accessing the relationships of an entity instance, whose class inherits from another entity class. For entity instances, whose classes do not inherit from another entity class, lazy loading of their relationships works as expected.

I had a look at the proxy objects and verified that they are present and override the **get method with an implementation containing a call to the load() method. Still, the loading won't work for some reason.

This could be related to Bug DDC-1389 (http://www.doctrine-project.org/jira/browse/DDC-1389) which also happens exclusively in an inheritance scenario. Maybe the current implementation of inheritance is generally wrong or incomplete.

Originally created by @doctrinebot on GitHub (Sep 22, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user dalvarez: Lazy loading does not work for the relationships of an instance of an entity, whose class inherits from another entity class. Assume there are two entity classes, A and B, where A inherits from B. Now let $a be an instance of A, e. g. the result of "SELECT a FROM \A WHERE a.id = 1". Outputting $a will confirm it is a valid instance of a proxy object inheriting from A. Assume that the database row corresponding to $a contains a non-null foreign key that actually links to an existing row in another table, corresponding to another entity instance of a different class. Now, $a->someRelationship will always returns null in this scenario. I assume this is unintended behaviour, because clearly, the other entity should be lazily loaded on accessing it, and there is a value in the database. The fetch annotation attribute on that relationship has not been explicitly set, so I assume it is set to the default value, which, according to the docs, should be "lazy". The loading only fails when accessing the relationships of an entity instance, whose class inherits from another entity class. For entity instances, whose classes do not inherit from another entity class, lazy loading of their relationships works as expected. I had a look at the proxy objects and verified that they are present and override the **get method with an implementation containing a call to the load() method. Still, the loading won't work for some reason. This could be related to Bug [DDC-1389](http://www.doctrine-project.org/jira/browse/DDC-1389) (http://www.doctrine-project.org/jira/browse/[DDC-1389](http://www.doctrine-project.org/jira/browse/DDC-1389)) which also happens exclusively in an inheritance scenario. Maybe the current implementation of inheritance is generally wrong or incomplete.
admin added the Bug label 2026-01-22 13:23:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1741