Skip to content
Advertisement

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?

JavaScript

Advertisement

Answer

The following approach uses an association object instead of an association table to get a self-referencing many-to-many relationship:

JavaScript

This will have the following result:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement