mardi 2 juillet 2019

hasMany with additional information

I'd like to get the following working:

I got a UserGroup that should have discounts on a list of ProductGroups.

Example:

UserGroup

{
    "data": {
        "id": 2,
        "title": "Test",
        "discounts": null,
    }
}

ProductGroups

{
  "data": [
    {
      "id": 1,
      "title": "Group1"
    },
    {
      "id": 2,
      "title": "Group2"
    }
  ]
}

Expected result

UserGroup

{
  "data": {
    "id": 2,
    "title": "Test",
    "discounts": [
      {
        "productgroup_id": 1,
        "discount": 0
      },
      {
        "productgroup_id": 2,
        "discount": 10
      }
    ]
  }
}

So now I'd like to know: How to save this the best? First I thought about JSON. The problem: If the ProductGroup is being deleted, the UserGroup-discounts-JSON is not updated using a cascade.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2J6mlKe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire