I want to define a model that has a self-referential (or recursive) foreign key using SQLModel. (This relationship pattern is also sometimes referred to as an adjacency list.) The pure SQLAlchemy implementation is described here in their documentation. Let’s say I want to implement the basic tree structure as described in the SQLAlchemy example linked above, where I have a
Tag: adjacency-list
Construct a graph of nodes using adjacency list in Python
I have a Node class as below I am trying to construct a Graph using an adjacency list as below: In the above adjacency list that is indexed from 1, the index is the Node value i.e. Node.val and the list at that index are the neighbors i.e. Node.neighbors For e.g., for index 1: For index 2: and so on