答案 0 :(得分:0)
这在SQLAlchemy文档中称为Adjacency List Relationships,建议的模型结构如下:
class Node(Base):
__tablename__ = 'node'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('node.id'))
data = Column(String(50))
children = relationship("Node")