diff --git a/addons/api/addon/models/account.js b/addons/api/addon/models/account.js index 71b337f44..ff6b9d583 100644 --- a/addons/api/addon/models/account.js +++ b/addons/api/addon/models/account.js @@ -4,6 +4,13 @@ import { computed } from '@ember/object'; export default class AccountModel extends GeneratedAccountModel { + // =properties + + /** + * Account resource is nested within auth methods. + */ + nestedResource = true; + // =attributes /** diff --git a/addons/api/addon/models/host-set.js b/addons/api/addon/models/host-set.js index 61033dd79..6b4587ce6 100644 --- a/addons/api/addon/models/host-set.js +++ b/addons/api/addon/models/host-set.js @@ -2,6 +2,14 @@ import GeneratedHostSetModel from '../generated/models/host-set'; import { fragmentArray } from 'ember-data-model-fragments/attributes'; export default class HostSetModel extends GeneratedHostSetModel { + + // =properties + + /** + * Account resource is nested within auth methods. + */ + nestedResource = true; + // =attributes /** diff --git a/addons/api/addon/models/host.js b/addons/api/addon/models/host.js index 7748e023b..2b6957dc2 100644 --- a/addons/api/addon/models/host.js +++ b/addons/api/addon/models/host.js @@ -2,6 +2,14 @@ import GeneratedHostModel from '../generated/models/host'; import { fragment } from 'ember-data-model-fragments/attributes'; export default class HostModel extends GeneratedHostModel { + + // =properties + + /** + * Account resource is nested within auth methods. + */ + nestedResource = true; + /** * Attributes of this resource, if any, represented as a JSON fragment. * @type {FragmentHostAttributesModel} diff --git a/addons/api/addon/serializers/application.js b/addons/api/addon/serializers/application.js index a41c97730..cdbd2b56d 100644 --- a/addons/api/addon/serializers/application.js +++ b/addons/api/addon/serializers/application.js @@ -70,9 +70,11 @@ export default class ApplicationSerializer extends RESTSerializer { const serialized = super.serialize(...arguments); // Delete `scope` field delete serialized.scope; - // And serialize `scope_id` - const scope_id = snapshot?.attr('scope')?.attr('scope_id'); - if (scope_id) serialized.scope_id = scope_id; + // And serialize `scope_id` when not a nested resource + if(!snapshot?.record?.nestedResource) { + const scope_id = snapshot?.attr('scope')?.attr('scope_id'); + if (scope_id) serialized.scope_id = scope_id; + } return serialized; } diff --git a/addons/api/tests/unit/serializers/application-test.js b/addons/api/tests/unit/serializers/application-test.js index 3ab733e52..85702eac4 100644 --- a/addons/api/tests/unit/serializers/application-test.js +++ b/addons/api/tests/unit/serializers/application-test.js @@ -49,6 +49,21 @@ module('Unit | Serializer | application', function (hooks) { }); }); + test('it does not serialize scope_id when resource is nested', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const record = store.createRecord('account', { + name: 'Account', + description: 'Description', + scope: { + scope_id: 'global', + type: 'global', + }, + }); + const serializedRecord = record.serialize(); + assert.notOk(serializedRecord.scope_id); + }); + test('it serializes non-nullish version fields', function (assert) { assert.expect(2); const store = this.owner.lookup('service:store');