RelationManager problem with duplicate relationship
I have a N-M relation with RelationManager:
companies
and items
and pivot table company_item
. Pivot table has a boolean obsolete
field.
The problem is that I have a ToggleColumn on this obsolete field but when a company has two same items (same item_id
but different pivot_id
, the toggle will work on first ocurrence because is taking item_id
and should take pivot_id
for this.
Instead of taking pivot_id
(2809 and 5895) is taking the item_id
.2 Replies
I tried changing relation manager model to pivot model and works well, but when i want to attach or detach it crashes.
I found when I toggle, it executes a query with a select
... where items.id = '4' limit 1
so if there are duplicate items on same company it always returns first ocurrence.Solution
Ok, I solved with
allowDuplicates()
:
return $table
->allowDuplicates();