After 3 days fighting with ember data decided to ask community I’m trying to load data from my server to local storage according to TRANSITION.md on github
I did setup ember models:
App.Album = DS.Model.extend({
//...
cover: DS.belongsTo('cover', {async: true}) // tried without async as well...
});
App.Cover = DS.Model.extend({
album: DS.belongsTo('album')
});
And maked up serializer:
App.AlbumSerializer = DS.RESTSerializer.extend({
serializeIntoHash: function(hash, type, record, options) {
Ember.merge(hash, this.serialize(record, options));
},
extractSingle: function(store, type, payload, id) {
var covers = payload.albums.covers;
coverIds = covers.mapBy('id');
payload.covers = covers;
payload.albums.covers = coverIds;
//console.log(JSON.stringify(payload)); -> see below
return this._super.apply(this, arguments);
},
});
// console.log(JSON.stringify(payload)); → output:
{
"albums":{"id":"3","uid":"3","name":"wedding","url":"http://","covers":["5"]},
"covers":[{"id":"5","img":"img/test.jpeg","text":"test","album":"3"}]
}
I can see loaded data in chrome extension that cover for current album uploaded correctly. BUTTT…When I try to output it: I Route
model:function(){ return this.store.find(‘album’, 3); },
cover is always empty no matter what I try to do… I tried everything and almost give up please help…
**My server api returns json as below(embedded relationship):
{"albums":{"id":"3","uid":"3","name":"wedding","url":"http:\/\/placehold.it\/200x100","covers":[{"id":"5","img":"img/test.jpeg","text":"test","album":"3"}]}}