The docs specify that not providing detach with any parameter will remove all items.
// Remove projects with id 1, 2, 3
await user.related('projects').detach([1, 2, 3])
// Remove all projects
await user.related('projects').detach()
But, detach([]) will do the same. I just want to present the argument that providing an empty array, a state that can very often be naturally obtained through filtering, should not result in the dangerous outcome of clearing a table, but maybe just to exiting the query early.
The expectations can be subjective, especially when no input does clear all the rows. You can add a check before calling the detach method. For now, I am not changing any existing behaviour in the ORM.
The docs specify that not providing detach with any parameter will remove all items.
But,
detach([])
will do the same. I just want to present the argument that providing an empty array, a state that can very often be naturally obtained through filtering, should not result in the dangerous outcome of clearing a table, but maybe just to exiting the query early.