diff --git a/addons/api/addon/serializers/application.js b/addons/api/addon/serializers/application.js index 8eaf3c18b..0a9a23874 100644 --- a/addons/api/addon/serializers/application.js +++ b/addons/api/addon/serializers/application.js @@ -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; + } + } diff --git a/addons/api/tests/unit/models/scope-test.js b/addons/api/tests/unit/models/scope-test.js index 37762f9ce..ff309f64b 100644 --- a/addons/api/tests/unit/models/scope-test.js +++ b/addons/api/tests/unit/models/scope-test.js @@ -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');