Skip to content

Instantly share code, notes, and snippets.

@eccegordo
Last active June 12, 2018 18:50
Show Gist options
  • Save eccegordo/71046db53705a05f7239812f78662124 to your computer and use it in GitHub Desktop.
Save eccegordo/71046db53705a05f7239812f78662124 to your computer and use it in GitHub Desktop.
group and sub group promises Ember routes
import Ember from 'ember';
import RSVP from 'rsvp';
const { set, get } = Ember;
export default Ember.Route.extend({
model(params) {
let store = get(this, 'store');
let groupCollection = store.query('groupCollection', {
id: params.group_id,
sideload: [
"subgroupSelection",
"subGroupOne",
"subGroupTwo",
]
});
let subgroupSelections = groupCollection.then((groupCollectionResolved) => {
return groupCollectionResolved.get('subgroupSelections'); // a hasMany
});
let subGroupOne = subgroupSelections.then((subgroupSelectionsResolved) => {
return subgroupSelectionsResolved.get('subGroupOne'); // a belongsTo
});
let subGroupTwo = subgroupSelections.then((subgroupSelectionsResolved) => {
return subgroupSelectionsResolved.get('subGroupTwo'); // a belongsTo
});
return Ember.RSVP.hash({
groupCollection: groupCollection,
subgroupSelections: subgroupSelections,
subGroupOne: subGroupOne,
subGroupTwo: subGroupTwo
});
},
setupController(controller, hash) {
set(controller, 'groupCollection', hash.groupCollection);
set(controller, 'subgroupSelections', hash.subgroupSelections);
set(controller, 'subGroupOne', hash.subGroupOne);
set(controller, 'subGroupTwo', hash.subGroupTwo);
}
});
/*
Model Hierarchy looks likes this with a nested hierarchy three layers deep
groupCollection
groupCollection -> subgroupSelections
groupCollection -> subgroupSelections -> subGroupOne
groupCollection -> subgroupSelections -> subGroupTwo
- groupCollection
- -- hasMany subgroupSelections
- -- -- belongsTo subGroupOne
- -- -- belongsTo subGroupTwo
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment