soft deleting many to many pivot records?
Closed this issue · 2 comments
Hi,
Is it currently possible to soft delete pivot records?
Imagine I have a relationship like the following:
users
- id
- deleted_at
(many to many)
user_addresses
- id
- user_id fk
- address_id fk
- deleted_at <-- i want this
addresses
- id
- deleted_at
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
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
Great, I'll give that a shot. Thank you for the advice and quick response! 🤝