Parent property not loading from database

I am using Delphi 13.1 Pro with Aurelius 5.27.

I created a sample application that uses a root, branch, leaf node structure. Root and branch nodes can be parent nodes (containers), and branch and leaf nodes can be child nodes(items in the container).

I generated a SQLite database using a TDatabase manager and filled the tables with test data. I confirmed the data is in the database. However, when I load child node instances to create a TTreeView, most nodes do not retrieve their parent instances. Those contained in the root node do. Those in a branch node don't.

Please advise how to fix this.

Node Project.zip (82.3 KB)

I've attached a zip file with the project.

Node Project 2.zip (81.7 KB)

I worked with this further and partially solved the problem. The revised appication stores all objects in a single table. However, objects don't contain their parents when they are more than 3 levels deep in the hierarchy.

The application throws an exception when you click the "Show Data" button for level 3 objects (the levels are zero based). The Treeview is partially generated. Captions contain the object's name and level, with the level enclosed in parentheses. The list stops on a level 2 object. I believe this is a bug in Aurelius.

I've attached a zip file with the revised project.

You are hitting the Aurelius depth limit for loading nested objects.

Aurelius doesn't load the full object tree, one of the reasons is exactly this nested parent/child structure which could be even recursive, causing an infinite loop/stack overflow if Aurelius didn't have such limit.

One solution is to set MaxEagerFetchDepth to a higher value (Expand: Depth greater than 3 - #2 by wlandgraf).

But such solutions is best when you know in advance the depth of object tree you want to load. In this case, since this is a dynamic tree with an unknown depth, I suggest you make both Nodes and Parent to be lazy-loaded, so that they are dynamically loaded as you go deeper in the tree level.

Attached is your uModels.pas unit modified with lazy-loading for the mentioned properties.

uModels.pas (5.5 KB)