Save array in table with each item in array new entry

Hi,

I have been playing with an external api in codeless and have been succesfull in getting data and storing it in my table.

I have created a second table in relation to the first. I have a array from the external api that i want to store in the relational table. Each item in the array needs its own entry in the table.

How could i achieve this? Or is it not possible perhaps?

Regards,
Thomas

Do you want to store a collection of items in the second table and relate these items to an object from the first table?

Hi Mark,

In the json i get from the api there is 1 property that is an array. The other properties in the json are either string value, date, image. I need a way to deconstruct the array. So that the string values that are stored in the array can all get their own entry in the second table.

I got close but it got stored as a single entry in the table.

If i can deconstruct the array, i can then reuse the seperate value’s.

Regards,
Thomas

Could you please show what you came up with? Also please attach a screenshot of your table schema (from the Visual Modeler tab in backendless console). It will help in understanding what you’re trying to do.

Regards,
Mark

This is my codeless logic. Everything works except for the add object relations. What i have now is wrong, i’ve been testing all kind of things looking through older threads on the support forum.

This is the relation between the 2 tables.

Regards,
Thomas

The genres relationship column is declared in the Movie table. But in your code, you’re updating the relationship in the Genre table, that is wrong:
Codeless - Backendless Support 2022-01-15 15-56-51

Also, the Deep Save block, will create all the relationships for you automatically. You should be able to pass the genres property in Deep Save with the corresponding values and the related objects will be created.

Important: The related collection must be a list of objects. If it is a list of strings, it will not work.

Regards,
Mark

Yea, i was rewatching your youtube video, saw the mistake and changed it to Movie.

codeless

So having it like this will be good? The genre will be put into the genre table? and then linked to the Movie table?

I tested the first image and it didn’t work because it wasn’t a list. Now i tried this:

It worked but this is how it gets saved in the Genre table:
Genre table

Any idea on how i can get it saved seperately? So each genre has its own row in the table.

Regards,
Thomas

This is what I referred to when in my “important” note in the previous message.

To save the genre elements as individual records, you need to transform the list of strings into a list of objects. Here’s a video about list transformations from our latest training course:

Regards,
Mark

Ok, i’ll try that out real quick.

Ok, i got it to work. This is my codeless block now and i saves each string in the array as an individual object.

Thanks for the help Mark.

1 Like