0
votes

I am trying to write an Ember-Data adapter for using the Rhom JavaScript ORM for my ember app. But I have no idea what the methods like 'find', createRecord, findAll, etc should return.

Is there any reference I can follow. I really dont understand what happens in the RESTAdapter. I see that there is an Ajax call.

I am planning on using the 1.0 version of Ember Data and so I referred the Transition Readme file here https://github.com/emberjs/data/blob/master/TRANSITION.md and it says at one place:

App.MyAdapter = DS.Adapter.extend({
  find: function(store, type, id) {
    return $.getJSON("/" + this.pluralize(type) + "/" + id);
  }
});

Does this mean I just can return whatever I want? like JSON or something?

And should I use Ember.RSVP.resolve() at the end of the methods like in https://github.com/rpflorence/ember-localstorage-adapter/blob/master/localstorage_adapter.js.

1
App.ApplicationAdapter instead of App.MyAdapter? - Connor Leech

1 Answers

1
votes

"find", ideally, would return a promise, like in the basic Adapter example you saw there:

App.MyAdapter = DS.Adapter.extend({
  find: function(store, type, id) {
    return $.getJSON("/" + this.pluralize(type) + "/" + id);
  }
});

The 'getJSON' returns a promise, and Ember-data knows how to deal with it.

findQuery is similar, but the result of the promise should be an array.