0
votes

My server uses sensorID as the primary key on my Sensor model. I've tried the following

App.SensorSerializer = DS.RESTSerializer.extend({
  primaryKey: "sensorID"
});

based on what I see in this test, but it's not working. I'm getting an error:

Error while loading route: Error: No model was found for '0'

I'm using a custom adapter. The response is JSONP:

jQuery203041337518650107086_1397489458691([{"sensorID":1,"address":"XXX, YYY","latitude":"nnnn","longitude":"mmmm"...

but when I inspect the data that gets returned, it's a normal array:

// App.SensorAdapter
findAll: function(store, type, sinceToken) {
  var url = 'http://blahblahblah/?callback=?';
  var query = { since: sinceToken };

  return new Ember.RSVP.Promise(function(resolve, reject) {
    jQuery.getJSON(url, query).then(function(data) {
      debugger;
      // data.forEach(function(s) {
      //   s.id = +s.sensorID;
      // });
      Ember.run(null, resolve, data);

    }, function(jqXHR) {
      jqXHR.then = null; // tame jQuery's ill mannered promises
      Ember.run(null, reject, jqXHR);
    });
  });

What is the correct syntax for Ember Data 1.0.0-beta.7?

1
Will you show the json you're receiving, it's likely you have an attribute 0 which ED is trying to find the model for. - Kingpin2k
that's only a portion of the json, but here's the link to the transition documentation explaining the proper format, github.com/emberjs/data/blob/master/TRANSITION.md - Kingpin2k

1 Answers

0
votes

Try this:

App.Adapter.map('App.Sensor', {
  primaryKey: 'sensorID'
});