Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 protected]","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?

like image 610
Kim Fransman Avatar asked Sep 03 '12 13:09

Kim Fransman


1 Answers

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.

like image 109
MilkyWayJoe Avatar answered Mar 07 '23 23:03

MilkyWayJoe