0
I have a relationship N:N and 3 tables: projeto
, pagamento
and projeto_pagamento
. In a form, I want to register a project and 5 payments, which would be the best way to perform this insertion?
I thought about doing a post on projeto
, an array post in pagamento
, then take the project ID and payment Ids in an array and do a post on projeto_pagamento
. Or it would be better to insert each payment separately instead of an array?
That way I could use a forEach
in the role of inserting payment and then projeto_pagamento
also. You can return the Ids of the entered data?
You can do the
POST
of the whole object and treat it in the way that suits the server– Sorack
Interestingly, I hadn’t thought of it this way. In terms of safety and best practices this would be legal?
– Fernando Zabin
I never stopped to search, but I prefer to do this way to "save" requests and client processing
– Sorack
Very good, I’ll test it like this, but as it is a
api
i must do the post in whichendpoint
? It may be in/projetos
or/pagamentos
really? Or create anotherendpoint
for this specific case, since it will be necessary to make an Index in each table?– Fernando Zabin
May
/projetos
even– Sorack