0

I have setup a test where I try to PUT an item after fetching it. It fails on the dates when PUT'ing though. The date fields below use DS.attr('date').

Versions:

Ember      : 1.1.1
Ember Data : 1.0.0-beta.4+canary.c15b8f80
Handlebars : 1.0.0
jQuery     : 1.9.1

Here's my code:

BuildingsController

App.BuildingsController = Ember.Controller.extend({
  actions: {
    createBuilding: function() {
      var store = this.get('store');

      store.find('building', 1729).then(function(building) {
        building.set('title', 'Test 123');
        building.save();
      });
    }
  }
});

Data returned from API when calling store.find:

{
 "building":{
  "id":"1729",
  "name":"Test 123",
  "sort":"1",
  "published_at":"2013-09-26 11:00:27",
  "source":"source test",
  "content":"<p>content test<\/p>",
  "excerpt":"<p>excerpt test<\/p>",
  "lat":"62.39039989300704",
  "lon":"17.341790199279785",
  "address":"address",
  "build_start":"2013-09-22",
  "build_end":"2013-09-23",
  "created_at":"2013-09-26 11:00:28",
  "updated_at":"2013-09-26 11:00:28"
 }
}

Data PUT to API:

{
 "address" : "address",
  "build_end" : "Mon, 23 Sep 2013 00:00:00 GMT",
  "build_start" : "Sun, 22 Sep 2013 00:00:00 GMT",
  "content" : "<p>content test</p>",
  "created_at" : "undefined, NaN undefined NaN NaN:NaN:NaN GMT",
  "excerpt" : "<p>excerpt test</p>",
  "lat" : 62.39039989300704,
  "lon" : 17.341790199279785,
  "name" : "Test 123",
  "published_at" : "undefined, NaN undefined NaN NaN:NaN:NaN GMT",
  "sort" : 1,
  "source" : "source test",
  "updated_at" : "undefined, NaN undefined NaN NaN:NaN:NaN GMT"
}
Stefan Edberg
  • 231
  • 2
  • 4
  • 15
  • What fails? Your server? I see that the PUT data has some human readable dates vs the more machine format in the data that came down, is that the issue you mean? – gerry3 Oct 25 '13 at 06:32
  • My API returns http 500 error when it tries to convert created_at, published_at and updated_at to timestamp and since Firebug outputs them like this I guessed the problem lied in Ember's default date format or something like that. – Stefan Edberg Oct 25 '13 at 11:56
  • can you try printing the building before you set it's title? That would help to debug it more. – VNarasimhaM Oct 25 '13 at 13:32

2 Answers2

0

You can use a custom attribute type (rather than DS.attr('date')) by registering a custom transform and handle serialization / deserialization manually:

DS.RESTAdapter.registerTransform("mydate", {
  deserialize: function(serialized) {
    // deserialize date here
    return deserialized;
  },

  serialize: function(deserialized) {
    // serialize date here
    return serialized;
  }
});

As described in this answer to What is the best way to modify the date format when ember-data does serialization?

Community
  • 1
  • 1
gerry3
  • 21,420
  • 9
  • 66
  • 74
0

I've been working with other projects and now I updated Ember from 1.1.1 to 1.1.2 which seem to have magically solved this problem. I'm guessing the update didn't have anything to do with my problem, though.

Thanks for taking your time.

// Stefan

Stefan Edberg
  • 231
  • 2
  • 4
  • 15