问题
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