refactor: relationships are expressed as objects {id} rather than string ID fields

This commit is contained in:
Randall Morey committed 2020-07-16 18:45:08 -04:00
1 parent 45b419e641
commit d9795daf1b
2 files changed
+21 -6

No files matched your search

+16 -1
View File
@@ -30,7 +30,7 @@ export default class ApplicationSerializer extends RESTSerializer {
* @return {string}
*/
keyForRelationship(rel) {
return `${underscore(rel)}_id`;
return underscore(rel);
}
/**
@@ -137,4 +137,19 @@ export default class ApplicationSerializer extends RESTSerializer {
);
}
/**
* Returns the default extraction with one difference. If the extracted
* relationship does not include a `type` field as required by JSON API
* (the Ember internal record representation), one is added.
* @override
* @param {Object} relationshipModelName
* @param {Object} relationshipHash
* @return {Object}
*/
extractRelationship(relationshipModelName/*, relationshipHash*/) {
const relationship = super.extractRelationship(...arguments);
if (!relationship.type) relationship.type = relationshipModelName;
return relationship;
}
}
+5 -5
View File
@@ -19,11 +19,11 @@ module('Unit | Model | scope', function(hooks) {
this.server.get('/v1/scopes', () => ({
items: [
{id: 'global', type: 'global'},
{id: 'o_1', type: 'org', scope_id: 'global'},
{id: 'o_2', type: 'org', scope_id: 'global'},
{id: 'p_1', type: 'project', scope_id: 'o_1'},
{id: 'p_2', type: 'project', scope_id: 'o_1'},
{id: 'p_3', type: 'project', scope_id: 'o_2'}
{id: 'o_1', type: 'org', scope: {id: 'global'}},
{id: 'o_2', type: 'org', scope: {id: 'global'}},
{id: 'p_1', type: 'project', scope: {id: 'o_1'}},
{id: 'p_2', type: 'project', scope: {id: 'o_1'}},
{id: 'p_3', type: 'project', scope: {id: 'o_2'}},
]
}));
const scopes = await store.findAll('scope');