I've got an Ember 2.x web app that needs to get data with hasMany relationships : Many "sites" that have many "servers" and many "clients".
//Site model
export default DS.Model.extend({
name: DS.attr('string', {defaultValue: ''}),
servers: DS.hasMany('server'),
clients: DS.hasMany('client')
})
//Server model
export default DS.Model.extend({
ip: DS.attr('string', {defaultValue: '0.0.0.0'})
alive: DS.attr('boolean'),
site: DS.belongsTo('site')
})
//Client model
export default DS.Model.extend({
ip: DS.attr('string', {defaultValue: '0.0.0.0'})
alive: DS.attr('boolean'),
site: DS.hasMany('site')
});
To fetch my the content, I do something like this :
return this.store.findAll('client').then(() => {
console.info('clients : OK');
return this.store.findAll('server');
}).then(() => {
console.info('servers : OK');
return this.store.findAll('site');
}).then(() => {
console.info('sites : OK');
});
That's, OK, everything is downloaded and appears on screen as expected.
My app have a Socket.IO client that receive some simple notification telling it that it should reload all "servers" (since the "alive" values have been updated). So I simply execute a findAll('servers'), since I only want to update the servers :
this.store.findAll('servers');
Chrome's Ember data inspector is updated with the new values but not my "sites" content in the web page.
My question is : Why ? I suppose the solution is not as magical as I was expected it to be but after many hours of research, I'm still not able to do it.
I'm not sure to it's the right way to do it neither. I've try many searches on google, but only found examples for Ember 1 that won't work with Ember 2 or that suggest to reload everything.
Aucun commentaire:
Enregistrer un commentaire