Repeater reordering violates unique constraint

Hi, I try to reorder my items and SQL throws violates unique constraint. When i clone a item it works but not when i reorder. Filament: 3.0.86 My code:
Forms\Components\Repeater::make('days')
->relationship()
->label('Days')
->cloneable()
->collapsible()
->collapsed()
->orderColumn('day')
->reorderableWithButtons()
->itemLabel(function (array $state) {
$labels = [];

if (isset($state['day']) && $state['day']) {
$labels[] = 'Day ' . $state['day'];
}

if (isset($state['nutrients']) && count($state['nutrients'])) {
$labels[] = "N" . count($state['nutrients']);
}

if (isset($state['oncePerDayNutrients']) && count($state['oncePerDayNutrients'])) {
$labels[] = "O" . count($state['oncePerDayNutrients']);
}

if (isset($state['lights']) && count($state['lights'])) {
$labels[] = "L" . count($state['lights']);
}

return count($labels) ? implode(' | ', $labels) : null;
})
Forms\Components\Repeater::make('days')
->relationship()
->label('Days')
->cloneable()
->collapsible()
->collapsed()
->orderColumn('day')
->reorderableWithButtons()
->itemLabel(function (array $state) {
$labels = [];

if (isset($state['day']) && $state['day']) {
$labels[] = 'Day ' . $state['day'];
}

if (isset($state['nutrients']) && count($state['nutrients'])) {
$labels[] = "N" . count($state['nutrients']);
}

if (isset($state['oncePerDayNutrients']) && count($state['oncePerDayNutrients'])) {
$labels[] = "O" . count($state['oncePerDayNutrients']);
}

if (isset($state['lights']) && count($state['lights'])) {
$labels[] = "L" . count($state['lights']);
}

return count($labels) ? implode(' | ', $labels) : null;
})
1 Reply
RamboRoland
RamboRolandOP14mo ago
When using Repeater with relationship it's not possible to apply unique on sort. Because all models are save individually. There will always be a item that already has the old sort value. There is two different solutions: 1. remove unique on sort column 2. don't use relationship and use json instead. This works because all data i s saved at the same time.
Want results from more Discord servers?
Add your server