SQLAlchemy many-to-many orphan deletion

后端 未结 4 2103
梦如初夏
梦如初夏 2021-02-15 13:06

I\'m trying to use SQLAlchemy to implement a basic users-groups model where users can have multiple groups and groups can have multiple users.

When a group becomes empty

4条回答
  •  醉话见心
    2021-02-15 13:08

    The way I've generally handled this is to have a function on your user or group called leave_group. When you want a user to leave a group, you call that function, and you can add any side effects you want into there. In the long term, this makes it easier to add more and more side effects. (For example when you want to check that someone is allowed to leave a group).

提交回复
热议问题