Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 处理自引用backref_Python_Sqlalchemy_Relationship - Fatal编程技术网

Python 处理自引用backref

Python 处理自引用backref,python,sqlalchemy,relationship,Python,Sqlalchemy,Relationship,如何设置自引用关系方案,以便可以获得具有一个或多个关系列的父项和子项?我希望能够延迟加载父模型和所有子模型 模型设置: class Test(Model): order = Column(Integer) parent_id = Column(Integer, ForeignKey('test.id')) parent = relationship('Test', foreign_keys=[parent_id], uselist=False) children

如何设置自引用关系方案,以便可以获得具有一个或多个
关系
列的父项和子项?我希望能够延迟加载父模型和所有子模型

模型设置:

class Test(Model):
    order = Column(Integer)

    parent_id = Column(Integer, ForeignKey('test.id'))
    parent = relationship('Test', foreign_keys=[parent_id], uselist=False)
    children = relationship(
        'Test', order_by='Test.order',
        collection_class=ordering_list('order', count_from=1))

?@让我相信你是完美的。正是我想要的。奇怪的是,我在谷歌搜索半天的时候没有发现它。哈哈。我有一个印象,谷歌现在过度搜索个人数据,如果你明白我的意思的话,它就错过了“全球最佳”。如果谷歌让我失望,我通常会在一台完全不同的计算机上进行搜索(比如我的个人电脑是linux时的windows等)