ENV: Ember-1.8.1, Ember-data-1.0
I was trying to refresh some data in store. But I didn't build an adapter.
The models and relationships was like:
// user
{
posts: DS.hasMany('post')
}
// post
{
user: DS.belongsTo('user')
}
Something I did to reload data was like:
function reload(postPayload)
{
// assume there are 8 records in postPayload
console.log(user.get('posts')); // first time: 0 records, second time: 8
store.unloadAll('post');
console.log(user.get('posts')); // first time: 0, second time: 0
store.pushPayload(payload);
console.log(user.get('posts')); // first time: 8, second time: 16
console.log(store.all('posts')); // first time: 8, second time: 8
}
// this could be called many times
$.getJSON(url, reload);
The Problem here is when I try to get posts through user.hasMany relationship, the result doubled. But it seemed to be ok if I use store.all('posts') to filter posts.
Please help!
Aucun commentaire:
Enregistrer un commentaire