json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Pushing to a nested array in a resource

Open bida2 opened this issue 4 years ago • 1 comments

Hello!

I have the following resources in my db.json file:

{
  "courses": [
    {
      "id": 1,
      "courseName": "Angular",
      "courseHours": 120,
      "courseStudentList": [
        {
          "id": 14,
          "studentName": "Kennster",
          "studentAge": 24
        }
      ],
      "courseTeacher": null
    },
    {
      "id": 2,
      "courseName": "Vue",
      "courseHours": 100,
      "courseStudentList": [
        {
          "id": 3,
          "studentName": "Mindy",
          "studentAge": 27
        },
        {
          "id": 4,
          "studentName": "Ashley",
          "studentAge": 22
        }
      ],
      "courseTeacher": {
        "id": 1,
        "teacherName": "Mr. Leon",
        "teacherDegree": "PHD"
      }
    }
  ]
}

I want to be able to add new objects to the courseStudentList array object property. Can this be done without custom routes?

bida2 avatar Jul 03 '21 12:07 bida2