Fixed Ember Data error when navigating to Staff screen

no issue

- if only some roles have been loaded, such as from embedded user records in posts, navigating to the Staff screen when invites exist for roles that have not yet been loaded would result in an Ember Data error
- the error occurs because we use `invite.role.*` in the template but we've specified `{async: false}` in the `belongsTo` relationship for `invite.role` which prevents Ember Data automatically querying the API
- by always fetching the roles list before fetching the invites list we prevent the error but we do introduce an extra API request in some circumstances
This commit is contained in:
Kevin Ansfield 2020-01-10 13:53:58 +00:00
parent a862cb6b6a
commit 190f2e905d

View File

@ -78,13 +78,9 @@ export default Controller.extend({
}
// ensure roles are loaded before invites. Invites do not have embedded
// role records which means Ember Data will try to fetch the roles
// automatically when invite.role is queried, loading roles first makes
// them available in memory and cuts down on network noise
let knownRoles = this.store.peekAll('role');
if (knownRoles.length <= 1) {
yield this.store.query('role', {limit: 'all'});
}
// role records which means Ember Data will throw errors when trying to
// read the invite.role data when the role has not yet been loaded
yield this.store.query('role', {limit: 'all'});
return yield this.store.query('invite', {limit: 'all'});
})