JohnC
JohnC

Reputation: 4148

Ember-data not updating model on PUT request?

With the current ember-data 0.13 is there a way to update a model from the response content of a PUT request?

In my REST api fields (such as updated_at) are set at the server during an object update and the client model needs to be updated with the content of the response from the PUT request.

Specifically, an updated_at property that's used for concurrency handling needs to be set from the PUT response.

Upvotes: 1

Views: 746

Answers (1)

JohnC
JohnC

Reputation: 4148

Figured it out. For future reference if the REST API returns a payload as a result of a PUT request it must not be inside an array.

I.E. this:

{
  "client": {
    "__v": 2,
    "_id": "51d47b5b3f7499341a00006a",        
    "created_at": "2013-07-03T19:28:27.868Z",
    "created_by": "51d47b5b3f7499341a000003",
    "name": "A1",        
    "updated_at": "2013-07-04T21:20:36.311Z",
    "updated_by": "51d47b5b3f7499341a000004",
  }
}

And not this:

{
  "client": [
    {
      "__v": 2,
      "_id": "51d47b5b3f7499341a00006a",
      "created_at": "2013-07-03T19:28:27.868Z",
      "created_by": "51d47b5b3f7499341a000003",
      "name": "A1",
      "updated_at": "2013-07-04T21:23:11.943Z",
      "updated_by": "51d47b5b3f7499341a000004",
    }
  ]
}

Upvotes: 3

Related Questions