deleting entities in cascade not working in ManyToMany relation

前端 未结 1 1882
终归单人心
终归单人心 2021-01-01 00:03

I have a parent entity Category and a child entity Article. They are defined by a ManyToMany relation. One article can be taged in one or more category and every Category ca

相关标签:
1条回答
  • 2021-01-01 00:28

    You can't do this using just cascading features as far as I can think of.

    A clean solution would be to create an listener which subscribes to the preRemove events. You can then check when a category is deleted and find all articles from that category which do not have any other categories and remove those as well.

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