From 9c81a3c2feb409d4ff75d6800cdafd01664b3af4 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Wed, 2 Dec 2020 17:16:48 -0800 Subject: [PATCH 1/2] [Cleanup]: Remove FULL_LINKS_ON_RELATIONSHIPS --- .../relationships/relationship-links-test.js | 579 +++++++++--------- .../canary-features/addon/default-features.ts | 1 - packages/canary-features/addon/index.ts | 1 - .../model/addon/-private/system/many-array.js | 11 +- .../-private/system/promise-many-array.js | 3 +- .../-private/system/model/internal-model.ts | 3 +- .../-private/system/references/reference.ts | 15 +- 7 files changed, 302 insertions(+), 311 deletions(-) diff --git a/packages/-ember-data/tests/integration/relationships/relationship-links-test.js b/packages/-ember-data/tests/integration/relationships/relationship-links-test.js index d5e09109457..ab86d663b0b 100644 --- a/packages/-ember-data/tests/integration/relationships/relationship-links-test.js +++ b/packages/-ember-data/tests/integration/relationships/relationship-links-test.js @@ -5,7 +5,6 @@ import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; -import { FULL_LINKS_ON_RELATIONSHIPS } from '@ember-data/canary-features'; import Model, { attr, hasMany } from '@ember-data/model'; import Store from '@ember-data/store'; @@ -19,341 +18,339 @@ module('JSON:API links access on relationships', function(hooks) { store = owner.lookup('service:store'); }); - if (FULL_LINKS_ON_RELATIONSHIPS) { - test('We can access links from a hasMany', async function(assert) { - class ApplicationAdapter extends EmberObject { - findRecord() {} - findHasMany() { - return resolve({ - data: [], - }); - } - shouldBackgroundReloadRecord() { - return false; - } - shouldReloadRecord() { - return false; - } + test('We can access links from a hasMany', async function(assert) { + class ApplicationAdapter extends EmberObject { + findRecord() {} + findHasMany() { + return resolve({ + data: [], + }); } - class User extends Model { - @attr name; - @hasMany('tool', { inverse: null, async: true }) - tools; + shouldBackgroundReloadRecord() { + return false; } - class Tool extends Model { - @attr name; + shouldReloadRecord() { + return false; } - class ApplicationSerializer extends EmberObject { - normalizeResponse(_, __, data) { - return data; - } + } + class User extends Model { + @attr name; + @hasMany('tool', { inverse: null, async: true }) + tools; + } + class Tool extends Model { + @attr name; + } + class ApplicationSerializer extends EmberObject { + normalizeResponse(_, __, data) { + return data; } - this.owner.register('adapter:application', ApplicationAdapter); - this.owner.register('serializer:application', ApplicationSerializer); - this.owner.register('model:user', User); - this.owner.register('model:tool', Tool); + } + this.owner.register('adapter:application', ApplicationAdapter); + this.owner.register('serializer:application', ApplicationSerializer); + this.owner.register('model:user', User); + this.owner.register('model:tool', Tool); - const user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: '@runspired', - }, - relationships: { - tools: { - links: { - self: '/the/original/path', - related: '/the/related/link', - first: '/the/related/link?page=1', - prev: null, - last: '/the/related/link?page=3', - next: '/the/related/link?page=2', - }, + const user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: '@runspired', + }, + relationships: { + tools: { + links: { + self: '/the/original/path', + related: '/the/related/link', + first: '/the/related/link?page=1', + prev: null, + last: '/the/related/link?page=3', + next: '/the/related/link?page=2', }, }, }, - }); + }, + }); - // Test we have access via the HasManyReference - const toolsRef = user.hasMany('tools'); - let links = toolsRef.links(); - assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); - assert.strictEqual(links.related, '/the/related/link', 'The related link is correctly available'); - assert.strictEqual(links.first, '/the/related/link?page=1', 'The first link is correctly available'); - assert.strictEqual(links.last, '/the/related/link?page=3', 'The last link is correctly available'); - assert.strictEqual(links.prev, null, 'The prev link is correctly available'); - assert.strictEqual(links.next, '/the/related/link?page=2', 'The next link is correctly available'); - assert.strictEqual(links.self, '/the/original/path', 'The self link is correctly available'); + // Test we have access via the HasManyReference + const toolsRef = user.hasMany('tools'); + let links = toolsRef.links(); + assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); + assert.strictEqual(links.related, '/the/related/link', 'The related link is correctly available'); + assert.strictEqual(links.first, '/the/related/link?page=1', 'The first link is correctly available'); + assert.strictEqual(links.last, '/the/related/link?page=3', 'The last link is correctly available'); + assert.strictEqual(links.prev, null, 'The prev link is correctly available'); + assert.strictEqual(links.next, '/the/related/link?page=2', 'The next link is correctly available'); + assert.strictEqual(links.self, '/the/original/path', 'The self link is correctly available'); - // Test we have access via the ManyArray - const toolsRel = await user.tools; - links = toolsRel.links; - assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); - assert.strictEqual(links.related, '/the/related/link', 'The related link is correctly available'); - assert.strictEqual(links.first, '/the/related/link?page=1', 'The first link is correctly available'); - assert.strictEqual(links.last, '/the/related/link?page=3', 'The last link is correctly available'); - assert.strictEqual(links.prev, null, 'The prev link is correctly available'); - assert.strictEqual(links.next, '/the/related/link?page=2', 'The next link is correctly available'); - assert.strictEqual(links.self, '/the/original/path', 'The self link is correctly available'); - }); + // Test we have access via the ManyArray + const toolsRel = await user.tools; + links = toolsRel.links; + assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); + assert.strictEqual(links.related, '/the/related/link', 'The related link is correctly available'); + assert.strictEqual(links.first, '/the/related/link?page=1', 'The first link is correctly available'); + assert.strictEqual(links.last, '/the/related/link?page=3', 'The last link is correctly available'); + assert.strictEqual(links.prev, null, 'The prev link is correctly available'); + assert.strictEqual(links.next, '/the/related/link?page=2', 'The next link is correctly available'); + assert.strictEqual(links.self, '/the/original/path', 'The self link is correctly available'); + }); - test('We preserve { href } link objects', async function(assert) { - class ApplicationAdapter extends EmberObject { - findRecord() {} - findHasMany() { - return resolve({ - data: [], - }); - } - shouldBackgroundReloadRecord() { - return false; - } - shouldReloadRecord() { - return false; - } + test('We preserve { href } link objects', async function(assert) { + class ApplicationAdapter extends EmberObject { + findRecord() {} + findHasMany() { + return resolve({ + data: [], + }); } - class User extends Model { - @attr name; - @hasMany('tool', { inverse: null, async: true }) - tools; + shouldBackgroundReloadRecord() { + return false; } - class Tool extends Model { - @attr name; + shouldReloadRecord() { + return false; } - class ApplicationSerializer extends EmberObject { - normalizeResponse(_, __, data) { - return data; - } + } + class User extends Model { + @attr name; + @hasMany('tool', { inverse: null, async: true }) + tools; + } + class Tool extends Model { + @attr name; + } + class ApplicationSerializer extends EmberObject { + normalizeResponse(_, __, data) { + return data; } - this.owner.register('adapter:application', ApplicationAdapter); - this.owner.register('serializer:application', ApplicationSerializer); - this.owner.register('model:user', User); - this.owner.register('model:tool', Tool); + } + this.owner.register('adapter:application', ApplicationAdapter); + this.owner.register('serializer:application', ApplicationSerializer); + this.owner.register('model:user', User); + this.owner.register('model:tool', Tool); - const user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: '@runspired', - }, - relationships: { - tools: { - links: { - self: { href: '/the/original/path' }, - related: { href: '/the/related/link' }, - first: { href: '/the/related/link?page=1' }, - prev: null, - last: { href: '/the/related/link?page=3' }, - next: { href: '/the/related/link?page=2' }, - }, + const user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: '@runspired', + }, + relationships: { + tools: { + links: { + self: { href: '/the/original/path' }, + related: { href: '/the/related/link' }, + first: { href: '/the/related/link?page=1' }, + prev: null, + last: { href: '/the/related/link?page=3' }, + next: { href: '/the/related/link?page=2' }, }, }, }, - }); + }, + }); - // Test we have access via the HasManyReference - const toolsRef = user.hasMany('tools'); - let links = toolsRef.links(); - assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); - assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); - assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); - assert.deepEqual(links.prev, null, 'The prev link is correctly available'); - assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); - assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); + // Test we have access via the HasManyReference + const toolsRef = user.hasMany('tools'); + let links = toolsRef.links(); + assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); + assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); + assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); + assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); + assert.deepEqual(links.prev, null, 'The prev link is correctly available'); + assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); + assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); - // Test we have access via the ManyArray - const toolsRel = await user.tools; - links = toolsRel.links; - assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); - assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); - assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); - assert.deepEqual(links.prev, null, 'The prev link is correctly available'); - assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); - assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); - }); + // Test we have access via the ManyArray + const toolsRel = await user.tools; + links = toolsRel.links; + assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); + assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); + assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); + assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); + assert.deepEqual(links.prev, null, 'The prev link is correctly available'); + assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); + assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); + }); - test('We unwrap the { href } link object when related link is accessed directly', async function(assert) { - class ApplicationAdapter extends EmberObject { - findRecord() {} - findHasMany() { - return resolve({ - data: [], - }); - } - shouldBackgroundReloadRecord() { - return false; - } - shouldReloadRecord() { - return false; - } + test('We unwrap the { href } link object when related link is accessed directly', async function(assert) { + class ApplicationAdapter extends EmberObject { + findRecord() {} + findHasMany() { + return resolve({ + data: [], + }); } - class User extends Model { - @attr name; - @hasMany('tool', { inverse: null, async: true }) - tools; + shouldBackgroundReloadRecord() { + return false; } - class Tool extends Model { - @attr name; + shouldReloadRecord() { + return false; } - class ApplicationSerializer extends EmberObject { - normalizeResponse(_, __, data) { - return data; - } + } + class User extends Model { + @attr name; + @hasMany('tool', { inverse: null, async: true }) + tools; + } + class Tool extends Model { + @attr name; + } + class ApplicationSerializer extends EmberObject { + normalizeResponse(_, __, data) { + return data; } - this.owner.register('adapter:application', ApplicationAdapter); - this.owner.register('serializer:application', ApplicationSerializer); - this.owner.register('model:user', User); - this.owner.register('model:tool', Tool); + } + this.owner.register('adapter:application', ApplicationAdapter); + this.owner.register('serializer:application', ApplicationSerializer); + this.owner.register('model:user', User); + this.owner.register('model:tool', Tool); - const user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: '@runspired', - }, - relationships: { - tools: { - links: { - related: { href: '/the/related/link' }, - }, + const user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: '@runspired', + }, + relationships: { + tools: { + links: { + related: { href: '/the/related/link' }, }, }, }, - }); + }, + }); - // Test we have access via the HasManyReference - const toolsRef = user.hasMany('tools'); - let links = toolsRef.links(); - assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); - assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); + // Test we have access via the HasManyReference + const toolsRef = user.hasMany('tools'); + let links = toolsRef.links(); + assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); + assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - let link = toolsRef.link(); - assert.strictEqual(link, '/the/related/link', 'The related link is unwrapped when accessed directly'); + let link = toolsRef.link(); + assert.strictEqual(link, '/the/related/link', 'The related link is unwrapped when accessed directly'); - // Test we have access via the ManyArray - const toolsRel = await user.tools; - links = toolsRel.links; - assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); - assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - }); + // Test we have access via the ManyArray + const toolsRel = await user.tools; + links = toolsRel.links; + assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); + assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); + }); - test('Links in the top-level of a relationship-document update the relationship links', async function(assert) { - class ApplicationAdapter extends EmberObject { - findRecord() {} - findHasMany() { - return resolve({ - data: [], - links: { - self: { href: '/some/other/path' }, - related: { href: '/the/new/related/link?page=3' }, - first: { href: '/the/new/related/link?page=1' }, - prev: { href: '/the/new/related/link?page=2' }, - last: { href: '/the/new/related/link?page=5' }, - next: { href: '/the/new/related/link?page=4' }, - }, - }); - } - shouldBackgroundReloadRecord() { - return false; - } - shouldReloadRecord() { - return false; - } + test('Links in the top-level of a relationship-document update the relationship links', async function(assert) { + class ApplicationAdapter extends EmberObject { + findRecord() {} + findHasMany() { + return resolve({ + data: [], + links: { + self: { href: '/some/other/path' }, + related: { href: '/the/new/related/link?page=3' }, + first: { href: '/the/new/related/link?page=1' }, + prev: { href: '/the/new/related/link?page=2' }, + last: { href: '/the/new/related/link?page=5' }, + next: { href: '/the/new/related/link?page=4' }, + }, + }); } - class User extends Model { - @attr name; - @hasMany('tool', { inverse: null, async: true }) - tools; + shouldBackgroundReloadRecord() { + return false; } - class Tool extends Model { - @attr name; + shouldReloadRecord() { + return false; } - class ApplicationSerializer extends EmberObject { - normalizeResponse(_, __, data) { - return data; - } + } + class User extends Model { + @attr name; + @hasMany('tool', { inverse: null, async: true }) + tools; + } + class Tool extends Model { + @attr name; + } + class ApplicationSerializer extends EmberObject { + normalizeResponse(_, __, data) { + return data; } - this.owner.register('adapter:application', ApplicationAdapter); - this.owner.register('serializer:application', ApplicationSerializer); - this.owner.register('model:user', User); - this.owner.register('model:tool', Tool); + } + this.owner.register('adapter:application', ApplicationAdapter); + this.owner.register('serializer:application', ApplicationSerializer); + this.owner.register('model:user', User); + this.owner.register('model:tool', Tool); - const user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: '@runspired', - }, - relationships: { - tools: { - links: { - self: { href: '/the/original/path' }, - related: { href: '/the/related/link' }, - first: { href: '/the/related/link?page=1' }, - prev: null, - last: { href: '/the/related/link?page=3' }, - next: { href: '/the/related/link?page=2' }, - }, + const user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: '@runspired', + }, + relationships: { + tools: { + links: { + self: { href: '/the/original/path' }, + related: { href: '/the/related/link' }, + first: { href: '/the/related/link?page=1' }, + prev: null, + last: { href: '/the/related/link?page=3' }, + next: { href: '/the/related/link?page=2' }, }, }, }, - }); + }, + }); - // Test we have access via the HasManyReference - const toolsRef = user.hasMany('tools'); - let links = toolsRef.links(); - assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); - assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); - assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); - assert.deepEqual(links.prev, null, 'The prev link is correctly available'); - assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); - assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); + // Test we have access via the HasManyReference + const toolsRef = user.hasMany('tools'); + let links = toolsRef.links(); + assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); + assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); + assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); + assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); + assert.deepEqual(links.prev, null, 'The prev link is correctly available'); + assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); + assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); - // Test we have access via the PromiseManyArray - links = user.tools.links; - assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); - assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); - assert.deepEqual(links.prev, null, 'The prev link is correctly available'); - assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); - assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); + // Test we have access via the PromiseManyArray + links = user.tools.links; + assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); + assert.deepEqual(links.first, { href: '/the/related/link?page=1' }, 'The first link is correctly available'); + assert.deepEqual(links.last, { href: '/the/related/link?page=3' }, 'The last link is correctly available'); + assert.deepEqual(links.prev, null, 'The prev link is correctly available'); + assert.deepEqual(links.next, { href: '/the/related/link?page=2' }, 'The next link is correctly available'); + assert.deepEqual(links.self, { href: '/the/original/path' }, 'The self link is correctly available'); - // Make a request that returns top-level relationship links - const toolsRel = await user.tools; + // Make a request that returns top-level relationship links + const toolsRel = await user.tools; - links = toolsRef.links(); - assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); - assert.deepEqual( - links.related, - { href: '/the/new/related/link?page=3' }, - 'The related link is correctly available' - ); - assert.deepEqual(links.first, { href: '/the/new/related/link?page=1' }, 'The first link is correctly available'); - assert.deepEqual(links.last, { href: '/the/new/related/link?page=5' }, 'The last link is correctly available'); - assert.deepEqual(links.prev, { href: '/the/new/related/link?page=2' }, 'The prev link is correctly available'); - assert.deepEqual(links.next, { href: '/the/new/related/link?page=4' }, 'The next link is correctly available'); - assert.deepEqual(links.self, { href: '/some/other/path' }, 'The self link is correctly available'); + links = toolsRef.links(); + assert.strictEqual(!!links, true, 'We have a links value on the relationship HasManyReference'); + assert.deepEqual( + links.related, + { href: '/the/new/related/link?page=3' }, + 'The related link is correctly available' + ); + assert.deepEqual(links.first, { href: '/the/new/related/link?page=1' }, 'The first link is correctly available'); + assert.deepEqual(links.last, { href: '/the/new/related/link?page=5' }, 'The last link is correctly available'); + assert.deepEqual(links.prev, { href: '/the/new/related/link?page=2' }, 'The prev link is correctly available'); + assert.deepEqual(links.next, { href: '/the/new/related/link?page=4' }, 'The next link is correctly available'); + assert.deepEqual(links.self, { href: '/some/other/path' }, 'The self link is correctly available'); - // Test we have access via the ManyArray - links = toolsRel.links; - assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); - assert.deepEqual( - links.related, - { href: '/the/new/related/link?page=3' }, - 'The related link is correctly available' - ); - assert.deepEqual(links.first, { href: '/the/new/related/link?page=1' }, 'The first link is correctly available'); - assert.deepEqual(links.last, { href: '/the/new/related/link?page=5' }, 'The last link is correctly available'); - assert.deepEqual(links.prev, { href: '/the/new/related/link?page=2' }, 'The prev link is correctly available'); - assert.deepEqual(links.next, { href: '/the/new/related/link?page=4' }, 'The next link is correctly available'); - assert.deepEqual(links.self, { href: '/some/other/path' }, 'The self link is correctly available'); - }); - } + // Test we have access via the ManyArray + links = toolsRel.links; + assert.strictEqual(!!links, true, 'We have a links value on the relationship ManyArray'); + assert.deepEqual( + links.related, + { href: '/the/new/related/link?page=3' }, + 'The related link is correctly available' + ); + assert.deepEqual(links.first, { href: '/the/new/related/link?page=1' }, 'The first link is correctly available'); + assert.deepEqual(links.last, { href: '/the/new/related/link?page=5' }, 'The last link is correctly available'); + assert.deepEqual(links.prev, { href: '/the/new/related/link?page=2' }, 'The prev link is correctly available'); + assert.deepEqual(links.next, { href: '/the/new/related/link?page=4' }, 'The next link is correctly available'); + assert.deepEqual(links.self, { href: '/some/other/path' }, 'The self link is correctly available'); + }); }); diff --git a/packages/canary-features/addon/default-features.ts b/packages/canary-features/addon/default-features.ts index 3adca3996ed..fbeb2b9cc36 100644 --- a/packages/canary-features/addon/default-features.ts +++ b/packages/canary-features/addon/default-features.ts @@ -176,7 +176,6 @@ export default { IDENTIFIERS: true, REQUEST_SERVICE: null, CUSTOM_MODEL_CLASS: null, - FULL_LINKS_ON_RELATIONSHIPS: true, RECORD_ARRAY_MANAGER_IDENTIFIERS: true, REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT: null, }; diff --git a/packages/canary-features/addon/index.ts b/packages/canary-features/addon/index.ts index 172e245e02e..1dd06110631 100644 --- a/packages/canary-features/addon/index.ts +++ b/packages/canary-features/addon/index.ts @@ -37,7 +37,6 @@ export const RECORD_DATA_STATE = featureValue(FEATURES.RECORD_DATA_STATE); export const REQUEST_SERVICE = featureValue(FEATURES.REQUEST_SERVICE); export const IDENTIFIERS = featureValue(FEATURES.IDENTIFIERS); export const CUSTOM_MODEL_CLASS = featureValue(FEATURES.CUSTOM_MODEL_CLASS); -export const FULL_LINKS_ON_RELATIONSHIPS = featureValue(FEATURES.FULL_LINKS_ON_RELATIONSHIPS); export const RECORD_ARRAY_MANAGER_IDENTIFIERS = featureValue(FEATURES.RECORD_ARRAY_MANAGER_IDENTIFIERS); export const REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT = featureValue( FEATURES.REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT diff --git a/packages/model/addon/-private/system/many-array.js b/packages/model/addon/-private/system/many-array.js index 927cd5acaa1..c5655ee86bf 100644 --- a/packages/model/addon/-private/system/many-array.js +++ b/packages/model/addon/-private/system/many-array.js @@ -8,7 +8,7 @@ import EmberObject, { get } from '@ember/object'; import { all } from 'rsvp'; -import { CUSTOM_MODEL_CLASS, FULL_LINKS_ON_RELATIONSHIPS } from '@ember-data/canary-features'; +import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features'; import { _objectIsAlive, DeprecatedEvented, diffArray, PromiseArray, recordDataFor } from '@ember-data/store/-private'; /** @@ -245,14 +245,15 @@ export default EmberObject.extend(MutableArray, DeprecatedEvented, { let jsonApi = this.get('recordData').getHasMany(this.get('key')); // TODO this is odd, why should ManyArray ever tell itself to resync? let internalModels = this.store._getHasManyByJsonApiResource(jsonApi); + if (jsonApi.meta) { this.set('meta', jsonApi.meta); } - if (FULL_LINKS_ON_RELATIONSHIPS) { - if (jsonApi.links) { - this.set('links', jsonApi.links); - } + + if (jsonApi.links) { + this.set('links', jsonApi.links); } + this.flushCanonical(internalModels, true); }, diff --git a/packages/model/addon/-private/system/promise-many-array.js b/packages/model/addon/-private/system/promise-many-array.js index f31cf629296..2bb389214c4 100644 --- a/packages/model/addon/-private/system/promise-many-array.js +++ b/packages/model/addon/-private/system/promise-many-array.js @@ -4,7 +4,6 @@ import { reads } from '@ember/object/computed'; import { Promise } from 'rsvp'; -import { FULL_LINKS_ON_RELATIONSHIPS } from '@ember-data/canary-features'; import { PromiseArray } from '@ember-data/store/-private'; /** @@ -29,7 +28,7 @@ import { PromiseArray } from '@ember-data/store/-private'; @private */ const PromiseManyArray = PromiseArray.extend({ - links: FULL_LINKS_ON_RELATIONSHIPS ? reads('content.links') : undefined, + links: reads('content.links'), reload(options) { assert('You are trying to reload an async manyArray before it has been created', get(this, 'content')); this.set('promise', this.get('content').reload(options)); diff --git a/packages/store/addon/-private/system/model/internal-model.ts b/packages/store/addon/-private/system/model/internal-model.ts index 298da5f57f3..889e278f2df 100644 --- a/packages/store/addon/-private/system/model/internal-model.ts +++ b/packages/store/addon/-private/system/model/internal-model.ts @@ -12,7 +12,6 @@ import RSVP, { Promise } from 'rsvp'; import { CUSTOM_MODEL_CLASS, - FULL_LINKS_ON_RELATIONSHIPS, RECORD_DATA_ERRORS, RECORD_DATA_STATE, REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT, @@ -739,7 +738,7 @@ export default class InternalModel { type: this.store.modelFor(relationshipMeta.type), recordData: this._recordData, meta: jsonApi.meta, - links: FULL_LINKS_ON_RELATIONSHIPS ? jsonApi.links : undefined, + links: jsonApi.links, key, isPolymorphic: relationshipMeta.options.polymorphic, initialState: initialState.slice(), diff --git a/packages/store/addon/-private/system/references/reference.ts b/packages/store/addon/-private/system/references/reference.ts index 6e1bb871951..0538224eaeb 100644 --- a/packages/store/addon/-private/system/references/reference.ts +++ b/packages/store/addon/-private/system/references/reference.ts @@ -1,6 +1,5 @@ import { deprecate } from '@ember/debug'; -import { FULL_LINKS_ON_RELATIONSHIPS } from '@ember-data/canary-features'; import { DEPRECATE_REFERENCE_INTERNAL_MODEL } from '@ember-data/private-build-infra/deprecations'; import { internalModelFactoryFor } from '../store/internal-model-factory'; @@ -157,6 +156,12 @@ abstract class Reference { return link || null; } + links(): PaginationLinks | null { + let resource = this._resource(); + + return resource && resource.links ? resource.links : null; + } + /** The meta data for the belongs-to relationship. @@ -206,14 +211,6 @@ abstract class Reference { } } -if (FULL_LINKS_ON_RELATIONSHIPS) { - Reference.prototype.links = function links(): PaginationLinks | null { - let resource = this._resource(); - - return resource && resource.links ? resource.links : null; - }; -} - if (DEPRECATE_REFERENCE_INTERNAL_MODEL) { Object.defineProperty(Reference.prototype, 'internalModel', { get() { From 38cbd3ce7f73a49f29ec6f06e770524a76608ef4 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 3 Dec 2020 07:36:08 -0800 Subject: [PATCH 2/2] keep ff around --- packages/canary-features/addon/default-features.ts | 1 + packages/canary-features/addon/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/canary-features/addon/default-features.ts b/packages/canary-features/addon/default-features.ts index fbeb2b9cc36..3adca3996ed 100644 --- a/packages/canary-features/addon/default-features.ts +++ b/packages/canary-features/addon/default-features.ts @@ -176,6 +176,7 @@ export default { IDENTIFIERS: true, REQUEST_SERVICE: null, CUSTOM_MODEL_CLASS: null, + FULL_LINKS_ON_RELATIONSHIPS: true, RECORD_ARRAY_MANAGER_IDENTIFIERS: true, REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT: null, }; diff --git a/packages/canary-features/addon/index.ts b/packages/canary-features/addon/index.ts index 1dd06110631..172e245e02e 100644 --- a/packages/canary-features/addon/index.ts +++ b/packages/canary-features/addon/index.ts @@ -37,6 +37,7 @@ export const RECORD_DATA_STATE = featureValue(FEATURES.RECORD_DATA_STATE); export const REQUEST_SERVICE = featureValue(FEATURES.REQUEST_SERVICE); export const IDENTIFIERS = featureValue(FEATURES.IDENTIFIERS); export const CUSTOM_MODEL_CLASS = featureValue(FEATURES.CUSTOM_MODEL_CLASS); +export const FULL_LINKS_ON_RELATIONSHIPS = featureValue(FEATURES.FULL_LINKS_ON_RELATIONSHIPS); export const RECORD_ARRAY_MANAGER_IDENTIFIERS = featureValue(FEATURES.RECORD_ARRAY_MANAGER_IDENTIFIERS); export const REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT = featureValue( FEATURES.REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT