Skip to content
Advertisement

Tag: self-referencing-table

How do I construct a self-referential/recursive SQLModel

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

Self-referencing many-to-many relationship with an association object in SQLAlchemy

I’ve found examples for a self-referencing many-to-many relationship with an association table. How can I achieve the same using an association object? The code below is based on: How can I achieve a self-referencing many-to-many relationship on the SQLAlchemy ORM back referencing to the same attribute? Answer The following approach uses an association object instead of an association table to

Advertisement