When saving/edit a resource create a new Model instance instead of update?
Hi,
I have the requirement to create a new resource when saving an form.
I'm using the
EditRecord
as my parent page but I'm overriding some methods.
For what I've seen I could override the save()
method.
What I'm doing is if a condition is met Instead of updating the model I create a new one and I assign it via $this->record
.
It seems to be working fine for the root model but this have two issues when relations comes in play.
The saveRelations()
chain is called this causes the child relations to be saved on the old $record.
To avoid this I can set the $record to null before the validation, this will fail on the saveRelationsBeforeChildren()
or similar method name.
While the "before" chain has been stopped from saving, at this point I have the new root Model saved.
I want to proceed with saving the relations, at this point the child relations are still saved with the wrong ID as the $record
is cached in most of the components.
Any idea to achieve this behavior?0 Replies