How to remodel hierarchical data as flat relationships with Datomic/Datascript?

I don’t have experience with Datomic. But if it is relational, then one to many relations, which is what hierarchical data is, you can think of it as a tree, is represented normally by having the children have a reference to the parent.

You can then find all children by querying them where parent ID = the parent. And thus recreate the hierarchy by joining children to parents.

Oh, and order should be explicit. So siblings that need to be ordered should have an Order attribute which can be sorted on to give you the desired order.

1 Like