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"}]}}