Post in table N:N with Node.js and Angularjs

Asked

Viewed 90 times

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?

  • 1

    You can do the POST of the whole object and treat it in the way that suits the server

  • Interestingly, I hadn’t thought of it this way. In terms of safety and best practices this would be legal?

  • 1

    I never stopped to search, but I prefer to do this way to "save" requests and client processing

  • Very good, I’ll test it like this, but as it is a api i must do the post in which endpoint? It may be in /projetos or /pagamentos really? Or create another endpoint for this specific case, since it will be necessary to make an Index in each table?

  • May /projetos even

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.