Delete rows inside relation in Adonis 5 #1341
-
Hi, Is it possible to remove data that is inside a relation? For example in Adonis js 4, you can achieve that like this: await user.post().delete() AdonisJs 5: await user.related("post").delete() // Error
await user.preload("post").delete() // Error |
Beta Was this translation helpful? Give feedback.
Answered by
thetutlage
Jul 27, 2020
Replies: 2 comments 2 replies
-
await user.preload('post');
await user.post.delete(); |
Beta Was this translation helpful? Give feedback.
1 reply
-
Here's how you can access the query builder of a relationship and then just chain the delete method on it. https://preview.adonisjs.com/guides/model-relations/introduction#access-to-the-direct-query-builder |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
dajpes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's how you can access the query builder of a relationship and then just chain the delete method on it.
https://preview.adonisjs.com/guides/model-relations/introduction#access-to-the-direct-query-builder