Create multiple records at once
Hi, I need create multiple records at once.
I am thinking on use handleRecordCreation function on my createPage but I do not know how to do this requirement.
At the moment of the creation I have the following data:
I need create 2 records on PurchaseOrder table and each one with the PurchaseOrderAssets respective.
Thanks in advance!
11 Replies
Is this a TableRepeater under
Activos
?Yes!
Is it setup with
->relationship()
? Actually, can you share this part of your code?Sure. Let me prepare that
The form is a little complex because I am using it in differents situations. I share below part of the code and attach the function which is creating the Table Repeater
@pboivin, thanks for helping me. The form has the logic we discuss on https://discord.com/channels/883083792112300104/1138141715266547752
PurchaseOrder.php
Ok, it's indeed a bit complex, forgive me for skimming a little bit 😅
It looks like you're using the
PurchaseOrderAssets
relationship on the repeater
Is this setup correctly on your model?Yes, it is ! haha
Yes, i just added the model code
here
But I believe I am not using correctly the form and relationship()
Right, thanks for pointing it out! The
hasMany()
looks of to me...
Just a note that ->default()
will only run on Create, not on Edit.
Is it working in your case, on Create?I am using the PurchaseOrderResource to display the fields I need (number, date, amount, order_status_id, business_partner_id ). But then I need to create as many records as different business_partner_id values in the TableRepeater.
Example records:
PurchaseOrder
(ID, number, date, amount, order_status_id, business_partner_id ):
[1; 'PO-1', '2023-08-09', 1000, 1, 8]
[2; 'PO-2', '2023-08-09', 2000, 1, 9]
PurchaseOrderAsset:
(quantity, price, amount, purchase_order_id, asset_id)
[1, 500, 500, 1, 1]
[2, 250, 500, 1, 2]
[1, 1500, 1500, 2, 3]
[5, 100, 500, 2, 4]
Yes, I am using it to init TableRepeater fields
Let me know if I am making understand myself
Ok. It looks like the
->relationship()
should be good for what you're trying to do, but it's possible I'm missing some detail. An alternative you could explore for saving manually is a lifecycle hook, like afterSave()
, on your page component.Thanks @pboivin , I will move to a custom page with a custom form to catch the submit function