Ember Data: A data hash was loaded … but no primary key 'undefined' was provided

拈花ヽ惹草 提交于 2019-12-22 11:15:56

问题


I'm trying to use Ember Data to load a model. The AJAX call to fetch the model seems to be successful but I get the following

Uncaught Error: assertion failed: A data hash was loaded for a model of type App.Account but no primary key 'undefined' was provided.

In ember-data.js:1128 it seems to be deferencing undefined for the primaryKey and not defaulting to 'id' when a model doesn't specify a primaryKey. But I've also tried being explicit with the primaryKey to no effect.

For completeness, here is my model:

App.Account = DS.Model.extend({
    portfolio_id: DS.attr('integer'),
    title: DS.attr('string'),
    user_id: DS.attr('integer'),
    url: 'investment_account'
});

and I'm loading the account with the following:

App.store.find(App.Account, account_id)

Any ideas?


回答1:


I "fixed" this by upgrading to the latest edge Ember Data (I was previously using both of the current distributions from both projects: 0.9.8.1 for ember.js and the four month old ember-data-latest.js on the ember-data github site). I'm still using the same ember.js distribution but upgrading Ember Data seems to have resolved this.



来源:https://stackoverflow.com/questions/10871953/ember-data-a-data-hash-was-loaded-but-no-primary-key-undefined-was-provid

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