0
votes

I use this guide to create a custom adapter for Ember Data: http://emberjs.com/api/data/classes/DS.Adapter.html

In my app.js I have the following:

App.store = DS.Store.create({
    adapter: 'MyAdapter'
});

I created the adapter:

App.MyAdapter = DS.Adapter.extend({
    createRecord: function(store, type, record) {
        console.log('create');
    },

    deleteRecord: function(store, type, record) {
        console.log('delete');
    },

    find: function(store, type, id) {
        console.log('find');
    },

    findAll: function(store, type, sinceToken) {
        console.log('findAll');
    },

    findQuery: function(store, type, query) {
        console.log('findQuery');
    },

    updateRecord: function(store, type, record) {
        console.log('updateRecord');
    }
});

And I created a model:

App.Post = DS.Model.extend({
    title: DS.attr,
    body: DS.attr,
    author: DS.attr
});

Then in a route I have:

this.store.createRecord('post', {
    title: 'Rails is Omakase',
    body: 'Lorem ipsum',
    author: 'asd'
});

var post = this.store.find('post');
console.log(post);

Unfortunately, this does not work, as there are several errors in console output:

  • Assertion failed: Unable to find fixtures for model type App.Post
  • Assertion failed: The response from a findAll must be an Array, not null
  • TypeError: Cannot read property 'map' of null.

So my first guess is, that it can't find my custom adapter, as there is also no logging if the function gets called (console.log('find')...). Is the documentation even up to date? Is the string MyAdapter correct? Shouldn't it be like this:

App.store = DS.Store.create({
    adapter: 'App.MyAdapter'
});

Nothing works. What have I done wrong?

One further question: Is there a good ember data adapter for web sockets?

1

1 Answers

0
votes

This documentation points to ember-data 1.0.0-beta.6 version and seems incorrect. In the meantime a fix was sent, but it is just avaliable on master branch.

You can follow the new documentation and update your code to use App.ApplicationAdapter:

var MyAdapter = DS.Adapter.extend({
  ...
});

App.ApplicationAdapter = MyAdapter;

Of course you will receive errors because the empty methods, but a findAll will be logged.