SQLAlchemy many-to-many orphan deletion

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

    I had the same problem about 3 months ago, i have a Post/Tags relation and wanted to delete unused Tags. I asked on irc and SA's author told me that cascades on many-to-many relations are not supported, which kind of makes sense since there is no "parent" in many-to-many.

    But extending SA is easy, you can probably use a AttributeExtension to check if the group became empty when is removed from a User and delete it from there.

提交回复
热议问题