Save() multiple records in 1 PUT request


#1

I have a model favorite. In the UI it is possible to drag and reorder these favortes.

When updating the order, i want to save this to the API. Is it possible to save multiple favorites by sending 1 request to the API? By default 1 request per favorite is send on favorite.save().

What I want is 1 PUT request formated something like this:

// PUT /api/users/1/favorites
// or 
// PUT /api/favorites
{
  "favorites": [
    {
      "id": 2,
      "order": 1
    }, {
      "id": 5,
      "order": 2
    }, {
      "id": 12,
      "order": 3
    }
  ]
}

#2

What is your relationship with favorites?

It’s a list of favorites for the user? It shouldn’t be better to have a relation hasMany from the user to favorites, and save the user?

Dracks.


#3

That would work only when setting { embedded: 'always' }?

Just found the documentation for DS.EmbeddedRecordsMixin Had a hard time finding DS.EmbeddedRecordsMixin.

Thanks for your advice!


#4

Sorry for the late response.

I think to only include the key, for example:

{
  "user":{
    ...
    "favorites":[1, 5, 7, 9 ]
  }
}