Prevent allowDuplicates() when using detach action
Hi! We've implement a MorphToMany relationship that allows for a user -> user_roles -> role relationship. The pivot table looks as follows:
- user_id
- role_id
- team_id
A user is allowed to have the same role multiple times as long as the team is different. By using
allowDuplicates()
attaching new records works as expected. However, when attempting to detach records it crashes, as an id column is expected when allowing duplicates. Is there anyway to get this to work? Thanks in advance!Solution:Jump to solution
Add an auto-incremementing id? Else we have no way of knowing which record to delete unless you adjust the detachh to be a custom detach that matches both the user_id, role_id and team_id
2 Replies
Solution
Add an auto-incremementing id? Else we have no way of knowing which record to delete unless you adjust the detachh to be a custom detach that matches both the user_id, role_id and team_id
Thanks for your reply! I did just that, made an custom action to match the id's and manually remove the record.