SQLAlchemy many-to-many orphan deletion

后端 未结 4 2116
梦如初夏
梦如初夏 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:18

    I think you want cascade='save, update, merge, expunge, refresh, delete-orphan'. This will prevent the "delete" cascade (which you get from "all") but maintain the "delete-orphan", which is what you're looking for, I think (delete when there are no more parents).

提交回复
热议问题