How to add or remove entity from a hasMany relationship?

How can I add or remove an entity from a hasMany relationship?
From and endpoint and from server-side

lifecycle hook beforeDelete.

Let’s assume that you have categories and articles, and you want to delete the category with all its articles.

Inside the beforeDelete lifecycle of Category, you should get all the relations IDs for all the articles, then you can delete them.