CODELESS - Save Data Object with relationship and dynamic structure

Hello everyone
I need to save datas with relationship with dynamic structure (some object have optionnal properties), which function should I use ? The deep save does not work because the structure must be fixed. Do you have a solution, I’m stuck i have this error :
“Deep save exception. Column ‘points_used’ in table ‘hubriseItems’ does not exists. All tables and columns must be present in the database before a transaction is executed.”,
“errorData”: {}
In this case i could not anticipate the property : points_used for example
Thank you very much
{
“private_ref”: “3345”,
“status”: “new”,
“service_type”: “delivery”,
“service_type_ref”: “WEBSITE-DEL”,
“expected_time”: “2021-06-24T11:30:00+02:00”,
“customer_id”: “ve343”,
“items”: [
{
“product_name”: “Margarita”,
“sku_ref”: “MAR-SM”,
“sku_name”: “Small”,
“price”: “9.00 EUR”,
“quantity”: “2”,
“options”: [
{
“option_list_name”: “Sauce”,
“name”: “Barbecue”,
“ref”: “BBQ”,
“price”: “1.00 EUR”,
“quantity”: 1
}
]
},
{
“product_name”: “Brownie”,
“sku_ref”: “BROWN”,
“price”: “3.00 EUR”,
“quantity”: “1”,
“deal_line”: {
“deal_key”: “0”,
“label”: “Dessert”
}
},
{
“product_name”: “Coke”,
“sku_ref”: “COK”,
“price”: “1.00 EUR”,
“quantity”: “1”,
“deal_line”: {
“deal_key”: “0”,
“label”: “Drink”
}
},
{
“product_name”: “Wings BBQ”,
“sku_ref”: “WBBQ”,
“price”: “4.00 EUR”,
“quantity”: “1”,
“points_used”: “5.0”
}
],
“loyalty_operations”: [
{
“ref”: “LOY”,
“delta”: “-5”,
“reason”: “Points used on order”
}
],
“charges”: [
{
“name”: “Delivery < 15 km”,
“ref”: “DEL”,
“price”: “1.50 EUR”
}
],
“payments”: [
{
“name”: “PayPal”,
“ref”: “PP”,
“amount”: “23.50 EUR”,
“info”: {
“email”: “john@doe.com
}
}
],
“discounts”: [
{
“name”: “5€ off your order”,
“ref”: “5OFF”,
“price_off”: “5.00 EUR”
}
],
“deals”: {
“0”: {
“name”: “Buy a dessert, get a drink for 1€”,
“ref”: “FREEDRINK”
}
}
}

Hi, @Maxime_Villeneuve

You might try creating all the columns that might exist in your table(s) first. And then, when you save the objects, just don’t pass values to those columns in objects that don’t have them. And for those records where you need them, they will already be created and the date will be saved.

Regards,
Marina

Thank you for your help,

How can i extract only data i need in a context argument when there are multiple objects.

Here you can see how i tried to do, in my case i have a list of items and each items have options .


Many thank

@Maxime_Villeneuve

The problem is that the hubriseItems table does not contain all the columns that you are saving data to. You first need to create all the columns in which you will save data during the transaction. You can create tables and columns under Data. According to the error the points_used column should be creaetd in the hubriseItems table.

Regards,
Marina

i understand, but i can’t anticipate all new columns, so probably i need to create column as the error occur.
How can i do this dynamically in codeless to be sure evey post request will be saved.

Regards

@Maxime_Villeneuve

If I understand you correctly and your database is dynamic. Then deepsave will not work for you in this case. Because, as I wrote earlier, all columns must be created before that.
So if you cannot anticipate all new columns try the option with the creation of objects and setting relations between them.

Regards,
Marina

Exactly, i will try on this way.

But have another blocking point to do this scenario, i don’t know how i can extract from the Method Argument an Array of different object.

In my case i need to separate items and options, save all object and them link them .

Schema :
An order have many items and each items have many options.

Thank you very much
Maxime

@Maxime_Villeneuve

But have another blocking point to do this scenario, i don’t know how i can extract from the Method Argument an Array of different object.

You need to add a new parameter to the API service and select its type as ANY Object.

The logic for creating a new object looks like this:
image

When calling the method, you need to add the required columns and values to the data1 object, like:
"data1": { "name": "Anna", "age": 10}

As a result, you will have a new object in your test table with the name and age columns created. Please make sure that dynamic schema is enabled in your application.

I can assume that the option you choose, where each user can modify your database by creating columns, can affect performance. Keep that in mind, please. Maybe it might be a good idea for you to choose an option where the database schema is strict? Would that work for you?

Regards,
Marina

Thank you for your help but it do not work for my structure because my data is imbricated.

It looks like :
Order {
“id”: “XXXXX”,
“propsName”: “xxxx”,

“items”: [
{
“propsName”: “xxxx”,
“objectId”: “string”,
“options”: [
{
“ownerId”: “string”,
“name”: “string”,

            }
        ]
    }
]

}

Regards