Organizational Company Tree


I am creating my entire database structure on aurelius, and so far it is going very well.

However i have a question, as newbie, how can a represent a tree as company organization? 

I mean, the concept of Aurelius is to map classes, so I am trying to think purelly on OOP, however it could be a problem:

//snip
TOrgNode = class
NodeID: TGui;
ParentNode: TOrgNode;
NodeType: TNodeType;
end

I belive that ParentNode could not be added to Aurelius that way, I have not tried yet, what is possible to do?

You can do that in Aurelius, but when retrieving a tree structure there will be a limit for the depth level which Aurelius can reach to load all the object tree (and this is for any association, not only recursive like this one). 

Note that building a tree is not trivial either with SQL or Aurelius. There are many techniques for building tree-like structures in databases, like adjacent lists or nested sets. The main problem with trees is not saving them, but rather querying on them.
I have built some accounting management system in the past, and one good approach, although redundant, is having a property named "Level" where you save string representation of the level node (like "002.010.018" for example) so it's easy to query them and build totals. But you will have to build a custom user interface to manage the tree and the level property.

In one of my current software I use this method with "level" column, it is easier to query for sure, however it limits the number of levels. For accounting it is fine few levels. But for Company tree including organizational structure can limit. 


And change the structure is event more difficult. 

However I will try to explore the options.

Thank you

I can't remember now, but I don't think there is a level limit. You can always have "002.006.001.062.041" and keep adding levels to the end of string, of course your database field must have enough characters to hold all levels.

You can still keep the Parent property for making structure change easier.

Just a last thought about the initial question:


What if I declare the ParentNode as a Lazy Loading:

TOrgNode = class
private
  [Association([TAssociationProp.Lazy], [])]
  [JoinColumn('NodeID', [])]
  ParentNode: Proxy<TOrgNode>;
  NodeID: TGui;

Is this valid? Is it going to load only the selected record and not going to load "recursively" until I access ParentNode? and so on... 

Yes, it will only load ParentNode if you access the property. And this has the advantage of allowing loading unlimited levels, since they are loaded on demand