[DDC-1390]  Lazy loading does not work for the relationships of an entity instance, whose class inherits from another entity class Created: 22/Sep/11  Updated: 06/Jan/13

Status: In Progress
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.1
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Daniel Alvarez Arribas Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Debian Linux 6.0, MySQL 5.0.51a


Attachments: File CommissionNoteCreatorResult.php     File ConsumerInvoiceExporterResult.php     File DataObject.php     File DataVersion.php     File DDC1390Test.php     File InvoiceCreatorResult.php     File Result.php     File Run.php    

 Description   

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.



 Comments   
Comment by Benjamin Eberlei [ 31/Oct/11 ]

Did this get fixed with the correction of your data?

Comment by Daniel Alvarez Arribas [ 01/Nov/11 ]

No it did not. This issue is completely unrelated to the other one.

For this, I have manually implemented workarounds, fetching the associations using DQL queries. Lazy loading in the inheritance scenario above still would not work.

Comment by Benjamin Eberlei [ 01/Nov/11 ]

So A is an entity in a hierachy A -> B, and "someRelationship" is a field on A or on B towards an Entity C that is in an inheritance hierachy or not?

Could you post parts of the mappings (entity docblock and the relationship)?

Comment by Daniel Alvarez Arribas [ 06/Nov/11 ]

Hey, thanks for taking care of this.

I attached the entities involved in the szenario to this issue.

I had problems lazy loading entities through the following associations:

Run.invoiceCreatorResult
Run.commissionNoteCreatorResult
Run.consumerInvoiceExporterResult

as well as

InvoiceCreatorResult.dataVersion
CommissionNoteCreatorResult.dataVersion
ConsumerInvoiceExporterResult.dataVersion

In this scenario, InvoiceCreatorResult, CommissionNoteCreatorResult and ConsumerInvoiceExporterResult all inherit from Result, which in turn inherits from a mapped superclass DataObject. Run and DataVersion inherit from DataObject directly.

The associations where lazy loading does not work are associations both to and from the entity classes InvoiceCreatorResult, CommissionNoteCreatorResult and ConsumerInvoiceExporterResult.

Comment by Benjamin Eberlei [ 18/Nov/11 ]

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.

Just a short Q on understanding: Why is $a a proxy of A if you select it explicitly?

Comment by Benjamin Eberlei [ 18/Nov/11 ]

This a working test-case with a model that i believe resembles yours exactly.

I also put your models into another test and ran schema validation on them, which works out without problems.

From the workflow with proxies, maybe DDC-1452 might be related to your issue?

Comment by Daniel Alvarez Arribas [ 18/Nov/11 ]

Regarding the proxy question, I just ment the query to be an example to further illustrate the type of $a. It was redundant and unnecessary though and probably misleading. Sorry for that. I did not select anything in the actual scenario. $a is merely some object of type A. No queries are involved.

Comment by Daniel Alvarez Arribas [ 18/Nov/11 ]

Have you been able to make the tests fail with the original data provided?

If not, I could set up a test case and post it.

Comment by Benjamin Eberlei [ 18/Nov/11 ]

No i only checked the validity of mappings with the original data. If you could setup a testcase that would be really great.

Comment by Daniel Alvarez Arribas [ 19/Nov/11 ]

I will set up a test case and upload it. I'll see if I can do it one of the next evenings.

Comment by Benjamin Eberlei [ 17/Dec/11 ]

I tried again, also extended DDC-1390, but it was impossible for me to reproduce this. I ran this against master, 2.1.x and 2.1.1 specifically.

Comment by Daniel Alvarez Arribas [ 05/Jan/13 ]

Sorry, I got swamped with work. Now I am working on this dedicatedly, testing against the latest release. Will let you know once I have a testcase.

Comment by Benjamin Eberlei [ 06/Jan/13 ]

Good to hear, thanks for the persistent work on this.

Generated at Thu Nov 27 20:52:29 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.