Download Lists of Owned Objects Using EmberData

I have 3 emberData models:

App.Product = DS.Model.extend({ page_title: DS.attr('string'), shop: DS.belongsTo('App.Shop'), user: DS.belongsTo('App.User') }); App.Shop = DS.Model.extend({ name: DS.attr('string'), }); App.User = DS.Model.extend({ name: DS.attr('string') }); 

and the JSON data is as follows:

 { products: [ { id: "1", page_title: "Product 1", user_id: "1", shop_id: "1", }, { id: "2", page_title: "Product 2", user_id: "2", shop_id: "1", } ], users: [ { id: "1", name: "User 1" }, { id: "2", name: "User 2" } ], shops: [ { id: "1", name: "Shop 1" } ] } 

But when I load the data, I got the following error:

 Assertion failed: Your server returned a hash with the key shops but you have no mapping for it 
+4
source share
1 answer

Well, the documentation is very unclear due to the fact that with the belongsTo relationship belongsTo key for the side load should be singular, and not multiple, even if its list is. Therefore, JSON should look like this:

 { products: [ { id: "1", page_title: "Product 1", user_id: "1", shop_id: "1", }, { id: "2", page_title: "Product 2", user_id: "2", shop_id: "1", } ], user: [ { id: "1", name: "User 1" }, { id: "2", name: "User 2" } ], shop: [ { id: "1", name: "Shop 1" } ] } 
+7
source

Source: https://habr.com/ru/post/1494577/


All Articles