【发布时间】:2010-11-14 05:44:06
【问题描述】:
应该如何使用 SQLAlchemy 将新节点添加到使用 Nested Set Model 实现的树中?
class Category(Base):
__tablename__ = 'categories'
id = Column(Integer, primary_key=True)
name = Column(String(128), nullable=False)
lft = Column(Integer, nullable=False, unique=True)
rgt = Column(Integer, nullable=False, unique=True)
我需要一个表上的触发器来为新节点分配lft 和rgt 并更新所有其他受影响的节点,但是定义节点位置的最佳方法是什么?我可以将新节点的parent_id 传递给构造函数,但是我如何将parent_id 传递给触发器?
【问题讨论】:
标签: python sql tree sqlalchemy nested-sets