lookinlab / adonis-lucid-soft-deletes

Addon for soft deletes AdonisJS Lucid ORM
MIT License
93 stars 7 forks source link

soft deleting many to many pivot records? #17

Closed mr-feek closed 1 year ago

mr-feek commented 1 year ago

Hi,

Is it currently possible to soft delete pivot records?

Imagine I have a relationship like the following:

users

(many to many) user_addresses

addresses

The library does work well when addresses are soft deleted, despite the pivot relationship still being there (user.addresses relationship is empty).

However, I would also like the pivot table record to be soft deleted as well (when calling the likes of detach). Is that possible out of the box with this package? I couldn't find any references in the codebase for pivot or many to many that looked like they handle the automatic pivot model that adonis creates

LookinGit commented 1 year ago

Hi, @mr-feek! Nope, plugin's nothing know about pivot tables for your model relations, you need self write this logic.

Example, try create for user_addresses a model UserAddress with deletedAt column and use soft-delete. And add to User model a relation through HasManyThrough for addresses

mr-feek commented 1 year ago

Great, I'll give that a shot. Thank you for the advice and quick response! 🤝