Associating the "categories" object in "products"; With the IDs that I need to associate with such a product, so for example "products 1" should receive the "categories" with the ID [1, 3, 4]. creating another array by combining the data between these objects.
{
"produtos": [{
"id": 1,
"nome": "Produto 1",
"categorias": [1, 3, 4]
}, {
"id": 2,
"nome": "Produto 2",
"categorias": [1, 2, 5]
}, {
"id": 3,
"nome": "Produto 3",
"categorias": [3, 1, 4]
}],
"categorias": [{
"id": 1,
"nome": "Categoria 1"
}, {
"id": 2,
"nome": "Categoria 2"
}, {
"id": 3,
"nome": "Categoria 3"
}, {
"id": 4,
"nome": "Categoria 4"
}, {
"id": 5,
"nome": "Categoria 5"
}]
}
Array result: { "products": [ { "id": 1, "name": "Product 1", "categories": [ {"id": 1, "name": "Category 1"}, {"id": 3, "name": "Category 3"}, {"id": 4, ] } ]