sqlalchemy.exc.CircularDependencyError: Circular dependency detected

后端 未结 1 701
太阳男子
太阳男子 2021-01-11 12:38

The business logic - One Category may have multiple (1:M) attributes, like Category \"Memory\" could have attributes Speed, Size, Type etc.

at the same time one Cat

相关标签:
1条回答
  • 2021-01-11 13:24

    Okay found the answer - use post_update in relationship http://docs.sqlalchemy.org/en/latest/orm/relationship_persistence.html#post-update

    so what I did is inside Category class is changed this:

    SortByAttribute = relationship(
        "Attribute",
        uselist=False,
        foreign_keys=[sortByAttribute],
        primaryjoin="Attribute.ID==Category.sortByAttribute"
    )
    

    to this:

    SortByAttribute = relationship(
        "Attribute",
        uselist=False,
        foreign_keys=[sortByAttribute],
        primaryjoin="Attribute.ID==Category.sortByAttribute",
        post_update=True
    )
    
    0 讨论(0)
提交回复
热议问题