How to insert mant-to-many object

41 Views Asked by At

I have two structures very similar to pests-owners, this is my structure:

{
    "name": "Contratti",
    "fields": {
      "rischicontratti": {
        "collection": "RischiContratti",
        "via": "Contratti"
      },
      "intervento": {
        "collection": "Interventi",
        "via": "Contratto"
      },
      "Numero": {
        "type": "string"
      },
      "Impresa": {
        "object": "Imprese"
      },
      "Oggetto": {
        "type": "string"
      }
  },
  {
    "name": "RischiContratti",
    "fields": {
      "Contratti": {
        "object": "Contratti"
      },
      "Rischio": {
        "object": "Rischi"
      }
    }
  },
{
    "name": "Rischi",
    "fields": {
      "rischicontratti": {
        "collection": "RischiContratti",
        "via": "Rischio"
      },
      "rischi_interventi": {
        "collection": "rischi_interventi",
        "via": "Rischio"
      },
      "Rischio": {
        "type": "string"
      }
  }

When I'm inserting a Contratto I want to also insert all related Rischi. Is there a way to post all in one call? Or do I have to post first the Contratto and then loop each Rischi?

0

There are 0 best solutions below