SQLAlchemy relationship with association_proxy problems

前端 未结 1 507
渐次进展
渐次进展 2021-01-06 16:04

I\'ve been wading through many website to try to understand what\'s going on, but I really need some direct help. I\'m sorry if I missed something obvious in the docs.

1条回答
  •  抹茶落季
    2021-01-06 16:47

    cascades go from owning parent to child object that gets deleted, so User.user_to_groups, Group.group_to_user:

    class UserToGroup(Base):
        __tablename__ = 'user_to_group'
        user_login = Column(String(60), ForeignKey(User.login), primary_key=True)
        group_name = Column(String(100), ForeignKey(Group.name), primary_key=True)
    
        user = relationship(User, backref=backref('user_to_groups', cascade='all, delete-orphan'))
        group = relationship(Group, backref=backref('group_to_user', cascade='all, delete-orphan'))
    

    0 讨论(0)
提交回复
热议问题