Lazy Loading Problem

I am using D 10.3 Rio Pro with the latest release of Aurelius with a Firebird 3 database to develop a student enrollment application for my employer.

I have created an enrollment contract class and a financial aid award class.  There is a one to zero or one relationship between the two. 

The enrollment contract class has a TFinAidAward association which I would like to lazy load.  Here is the code (which works without a problem):

    [JoinColumn('FIRST_DAY_OF_SCHOOL', [TColumnProp.Required], 'FIRST_DAY_OF_SCHOOL')]
    [JoinColumn('LAST_DAY_OF_SCHOOL', [TColumnProp.Required], 'LAST_DAY_OF_SCHOOL')]
    [JoinColumn('STUDENT_ID', [TColumnProp.Required], 'STUDENT_ID')]
    FFinAidAward: Proxy<TFinAidAward>;

If I change the Assocation attribute to  [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])], I get the following exception when a nil TFinAidAward object is returned.

"Project StudCont.exe raised exception class EAssertionFailed with message 'Proxy loading failed.  "TDocument" could not resolve property "FFinAidAward": results did not return a single object.
(Aurelius.Engine.ProxyController.pas, line 255)'."

Apparently, the referenced code asserts Objects.Count = 1, which is not the case.  If I don't use lazy loading however, there is no exception.

Is this a bug or something I am doing wrong?
The error indicates that you have two or more records in FinAidAward that are returned for a single TDocument entity. In other words, the values of columns FIRST_DAY_OF_SCHOOL, LAST_DAY_OF_SCHOOL and STUDENT_ID are not unique in table FinAidAward. Single it's a single-valued association, only one record (TFinAidAward object) should be returned.


That is not the case.  I have a unique index on the Financial Aid table for these fields.  At this time, there are only two record in the table and both are unique.  I only get this exception on record which return a nil TFinancial Aid object (i.e. ObjectCount = 0);

Please also read carefully my original post.  I don't get the exception for nil object if I use only [Association] for the attribute.  If I use [Association([Association([TAssociationProp.Lazy])], I do .  Shouldn't I get the exception either way?

Ok, it's clearer now. But, I suppose you don't have a foreign key enforcing the constraint, then?

Values in TDocument should refer to a valid record in FinancialAid table, unless they are NULL. Aurelius checks for null/empty values, and then returns nil. If the values are not nil, it tries to load the proxy and yes, raises an error if no object is retrieved.
That check is not enforced in eager mode because it just performs a LEFT JOIN between the two tables and read the results directly.

So, are you saying I need a foreign key to do lazy loading?

Not exactly a foreign key, but consistent data. We can consider change it, but this is the first case I hear about since Aurelius first version, so I assume it's a rare setup, where you have a join of fields that refer to non-existent records in the referred table.

I think it would be a good idea to change this at some point in the future. I think that lazy loading should would in this situation because the underlying query is a valid one. (e.g., it works with eager loading).

Having said that, I am okay with eager loading for this application, as there is a one to one relationship and TFinancialAid does not contain other objects.  Thank you for your help.