Hi,
The detach() with empty args suppose to delete all relations but it leaves junk data on the one side of relation.
Example :
We have a collection of books and a collection of authors and we want to relate them ManyToMany.
So books collection gonna have a field "author_ids" which is an array of ids and
authors also gonna have a field "book_ids" which is an array of ids.
When someone do $bookModel->authors()->detach(); all the relations of book with authors will be deleted.
But this clears only the field "book_ids" at authors collection leaving the data at field "authors_ids" at books collection intact.
@jenssegers can you confirm the issue?
Thanks leave a comment on how to resolve the issue
I find a way to work around this issue
So instead of using the $bookModel->authors()->detach();
you can use $bookModel->authors()->sync([]);
Note
This is working because this library has implement a sync() function for mongodb
but the detach() function is using Laravel's implementation so i think this is happening
because the Laravel's implementation use a pivot table for ManyToMany relations.
Most helpful comment
I find a way to work around this issue
So instead of using the
$bookModel->authors()->detach();you can use
$bookModel->authors()->sync([]);Note
This is working because this library has implement a
sync()function for mongodbbut the
detach()function is using Laravel's implementation so i think this is happeningbecause the Laravel's implementation use a pivot table for ManyToMany relations.