Hello, my friends! I have model with many nested async relationships, example:
//model1
export default DS.Model.extend({
fields1: DS.hasMany('model2',{async:true})
});
//model2
export default DS.Model.extend({
fields2: DS.hasMany('model3',{async:true})
});
When i use it in template - all is fine, promise resolve automatically. But i need to change model in controller (groups, calculate and etc.) and i had to manually handle all promises, as:
[code]import Ember from ‘ember’;
export default Ember.Controller.extend({
results:function(){
var all = ;
this.model.get(‘fields1’).then((fields1)=>{
fields1.forEach((field1)=>{
field1.get(‘fields2’).then((field2)=>{
all.concat(field2);
//Group and other operation withs all
here
this.set(‘all’, all);
});
});
});
}.observes(‘model’).on(‘init’) });[/code] And question, can i set what fields (or full) i need automatically resolve before use model in controller? Example:
//ROUTE
import Ember from 'ember';
export default Ember.Route.extend({
model:function(){
//LOAD ALL NESTED ASYNC FIELD !!!
return this.store.find('model1',{});
},
setupController:function(controller, model){
controller.set('model', model);
}
});
//controller
export default Ember.Controller.extend({
results:function(){
var all = [];
this.model.get('fields1').forEach((field1)=>{
all.concat(field1.get('fields2));
});
//Group and other operation withs `all` here
this.set('all', all);
}.observes('model').on('init')
});