vendredi 6 mars 2020

In Ember.js, ID of the sub-array elements are not passed within ajax put

I do a put call in ember.js and I am passing an object which contains an array. The element's id in this array are never passed to the backend, yet they do exist in the object.

I do a put call using

this.ajax.put('path', { data: object }.then();

The object that I am passing as the data has an array (example of the DTO).

object = {
  "array": [
    {
      "id": 0,
      "prop1",
      "prop2",
      "etc..."
    }
  ],
  "prop1",
  "prop2",
  "etc..."
}

The way that I construct each object from the array is by using

let objectArray = get(object, 'array');
let elementInObjectArray = //ajax call to get the element to add;
objectArray.pushObject(store.createRecord('element-in-object-array', { 
   id: elementInObjectArray.id,
   prop1: elementInObjectArray.prop1,
   etc...
})

Just before my put call, I log the id of the object.array.element.id, and they are defined and accessible (as string). (See image)

enter image description here

Yet, this id is never passed to the backend, and then I get a 404 from the server because the id is the primarykey. (See image of my put request payload)

enter image description here

I know that ember always return a string as an id when creating a record, but I don't think this is the reason why it fails since I would probably get more like a 400 for bad formatting. Right now, the id is just never passed.

How can I make sure that the id of the array element is passed in the call?




Aucun commentaire:

Enregistrer un commentaire