mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create record when there is a many to many relation

fmiccolis opened this issue · comments

Hi,
I have 2 tables called "event" and "agent".
This two tables are in a many to many relation represented by the table "partecipation".

I tried by adding to the event json the "agent" property as array of objects. These objects were composed only by the "id" property valued as the "agent" id. But this approach didn't work.

It is possible to create an "event" record and simultaneously add the "agents" all in one single POST request to the endpoint /records/event?

It is possible to create an "event" record and simultaneously add the "agents" all in one single POST request to the endpoint /records/event?

No, it is not possible to do so in a single POST request.

Ok, thanks for the fast reply.
For now I did a workaround by doing a batch create on the /records/partecipation endpoint after the creation of the "event".

Hoping for a enhancement, I close the issue.