0

I'm getting the following error in my Ember.js app.

    Error while processing route: books Cannot set property 'store' of undefined TypeError: Cannot set property 'store' of undefined
    at DS.Store.Ember.Object.extend.modelFor (http://localhost:8080/js/libs/ember-data.js:2986:19)
    at DS.Store.Ember.Object.extend.recordForId (http://localhost:8080/js/libs/ember-data.js:2437:17)
    at deserializeRecordId (http://localhost:8080/js/libs/ember-data.js:3355:23)
    at deserializeRecordIds (http://localhost:8080/js/libs/ember-data.js:3369:5)
    at http://localhost:8080/js/libs/ember-data.js:3335:7
    at http://localhost:8080/js/libs/ember-data.js:7117:16
    at http://localhost:8080/js/libs/ember.js:14899:20
    at Object.OrderedSet.forEach (http://localhost:8080/js/libs/ember.js:14741:14)
    at Object.Map.forEach (http://localhost:8080/js/libs/ember.js:14897:14)
    at Function.DS.Model.reopenClass.eachRelationship (http://localhost:8080/js/libs/ember-data.js:7116:38) 

I'm using

  • ember.js version 1.7.1 and
  • ember-data.js version 1.0.0-beta.5.

I have the following project:

window.App = Ember.Application.create();

App.ApplicationAdapter = DS.RESTAdapter.extend({
    host: 'http://localhost:8080'
});


App.Router.map(function() {
    this.resource('books', { path: '/' });
});

App.BooksRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('book');
    }
});


App.Author = DS.Model.extend({
    firstname: DS.attr('string'),
    lastname: DS.attr('string')
});

App.Book = DS.Model.extend({
    title: DS.attr('string'),
    authors: DS.hasMany('author')
});

and the following is my JSON response to http://localhost:8080/books.

{
   "books":
   [
       {
           "id": 0,
           "authors":
           [
               {
                   "id": 0,
                   "firstname": "Andrzej",
                   "lastname": "Sapkowski"
               }
           ],
           "title": "Zaklínač I: Poslední přání"
        },
        ...
   ]
}

When I remove the Author model and the authors relationship declaration, the application works fine.

The error message I'm getting doesn't reveal the cause and according to what I've found on the Internet, my code seems to be ok.

What's the problem?

2
  • Can you post the full stack trace of the error message, as well as the versions of Ember and Ember-Data you're using? Commented Oct 26, 2014 at 18:18
  • I upgraded ember.js to 1.7.1, but I'm still getting the same error. Commented Oct 26, 2014 at 18:33

1 Answer 1

1

Wow, I can't believe I didn't notice this, but your data isn't formatted properly. It should look something like this:

{
    "books": [{}, {}, {}],
    "authors": [{}, {}, {}]
}

This is explained in the REST adapter guide.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.