return single record with ember-data find() and multiple params

馋奶兔 提交于 2019-12-09 15:43:03

问题


I'm trying to do a find (with ember-data) on other params than the id, two params actually.

but all i get back is:

"Uncaught Error: assertion failed: Your server returned a hash with the key customer but you have no mappings".

After digging around in the code i see that the find method delegates to the findQuery method when given an hash, which create a DS.AdapterPopulatedRecordArray but I only return a single customer object in my json:

{"customer":{
"id":24857,"name":"Kim Fransman","id_number":"XXXX","email":"email@domain.com","type":"Person"}}

I can solve this by wrapping my json in a customers array and looping through them in my handlebars view but that feels very wrong.

Is there a way to do this with ember-data today?


回答1:


I had a similar issue and I opened a question here. Basically this is an undocumented property of the RESTAdapter that you have to configure according to your models. You'll have to define it similarly to this:

App.Store = DS.Store.extend({
  adapter: DS.RESTAdapter.create({
    bulkCommit: true,
    mappings: {
      // All your models will have to have a mapping defined,
      // like this...
      genres: 'App.Genre'
    }
  }),
  revision: 4
});

Check my question here: Ember-Data: How do "mappings" work

I hope it helps.



来源:https://stackoverflow.com/questions/12249211/return-single-record-with-ember-data-find-and-multiple-params

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