-
Hello 👋 🙃 , this is what I have so far const course = await Course.findOrFail(params.id);
course.preload("subscriptions", (query) => {
query.delete();
});
await course.delete(); My relationships are as follows: Course -> hasMany -> Subscription
Subscription -> Many-To-Many -> User Don't know how to gain access to that |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The course.related('subscriptions').detach() It's cover in documentation too https://preview.adonisjs.com/guides/model-relations/many-to-many#detach |
Beta Was this translation helpful? Give feedback.
-
I came up with something like this after all await course.preload("subscriptions");
course.subscriptions.map(async (subscription) => {
await subscription.related("users").detach();
await subscription.delete();
}); I was trying to avoid that |
Beta Was this translation helpful? Give feedback.
I came up with something like this after all
I was trying to avoid that
.map()
but it appears it's not possible