Replicate with relationship repeater updates original relation records but doesn't create new ones

Pretty much everything in the title. Replicating an invoice, showing the resource form in the replicate modal. When updating the repeating items, the form will update the original items instead of creating new ones. We also can't create the new items in the after method, as the items are not present in the provided $data. Any idea how to achieve that, or should we open an issue?
7 Replies
toeknee
toeknee3mo ago
You will need to adjust the replicate functionality. To first replicate the record, then replace the relationships with the updated id of the record
mathieutu
mathieutuOP3mo ago
Thanks for the answer. My goal is to not touch the current records, but to create new ones. By submitting the action, the original relationship items are updated, but not created at all.
toeknee
toeknee3mo ago
Correct, so you need to adjust the action. Please provide the code you are using and I'll tell you how to adjust it so it doesn't update. It sounds like you are not using the replciate functionality correctly.
mathieutu
mathieutuOP3mo ago
Pretty basic actually:
Tables\Actions\ReplicateAction::make()->form(fn (Form $form) => static::form($form)->columns(2))
Tables\Actions\ReplicateAction::make()->form(fn (Form $form) => static::form($form)->columns(2))
And the form contains the repeater
Forms\Components\Repeater::make('items')
->columnSpanFull()
->relationship()
->columns(3)
->schema([
...
Forms\Components\Repeater::make('items')
->columnSpanFull()
->relationship()
->columns(3)
->schema([
...
toeknee
toeknee2mo ago
That looks generally ok, you need to look into the replicateAction because if sounds like you have possibly assigned the relationships to record and the record values are just copying across and what you need to do is also replicate those too.
Hamburas
Hamburas2mo ago
gm
mathieutu
mathieutuOP2mo ago
@toeknee not sure to have understood. When looking at the executed queries, we clearly see that: - A query is made to update the previous items (children). I think it's not linked to the ReplicateAction, but the Repeater. - No new items are created. The new invoice (parent) has no items at all.

Did you find this page helpful?