Assertion failed: No model was found for '0' Django REST and Ember Adapter

守給你的承諾、 提交于 2019-12-11 05:08:56

问题


I'm getting the error with the following code:

App.SearchRoute = Ember.Route.extend({
    model: function(){
        return this.store.find('cabinets')
    }
});
App.SearchAdapter = DS.DjangoRESTAdapter.extend({
   namespace: 'rest_framework'
});

I created the model but its not formatting the JSON correctly and I'm not sure what I am doing wrong.

Also if I pump in this code instead:

App.Store = DS.DjangoRESTStore.extend({
 adapter: DS.DjangoRESTAdapter.create({
    namespace: "rest_framework"
 }),
 revision: 12
 });

I get an error on the extend method....

Here is my JSON return from a test.

0: {id:1, cabinet_name:HR Department, cabinet_security:1, status:1}

回答1:


What version of Ember Data are you using? If it's a 1.0, you need to use the version described here (https://github.com/emberjs/data/blob/master/TRANSITION.md) and not define the store like so. I'm pretty sure you were originally trying that though. Additionally, is your JSON really not coming with quotes around HR Department?

App.CabinetAdapter = DS.DjangoRESTAdapter.extend({
  namespace: 'rest_framework'
});



回答2:


Here is what chrome shows me

DEBUG: ------------------------------- ember.js:3231
DEBUG: Ember      : 1.3.0-beta.1+canary.628071a4 ember.js:3231
DEBUG: Ember Data : 1.0.0-beta.4+canary.e7996c4d ember.js:3231
DEBUG: Handlebars : 1.0.0 ember.js:3231
DEBUG: jQuery     : 1.10.2 ember.js:3231
DEBUG: ------------------------------- 

Oh yes there is quotes around I didnt notice that those didnt copy over from the debugger.

Here is what I have listed and now for some reason it works

DS.DjangoRESTSerializer = DS.RESTSerializer.extend();
DS.DjangoRESTAdapter = DS.RESTAdapter.extend({
      defaultSerializer: "DS/djangoREST"
});

App.Store = DS.Store.extend({
        revision: 12,
        adapter: DS.DjangoRESTAdapter.create()
});
App.SearchAdapter = DS.DjangoRESTAdapter.extend({
    namespace: 'rest_framework'
});


来源:https://stackoverflow.com/questions/20154265/assertion-failed-no-model-was-found-for-0-django-rest-and-ember-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!