-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implicit inverse key gen needs to utilize the related type for u…
…niqueness
- Loading branch information
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/record-data/tests/integration/graph/polymorphism/implicit-keys-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { module, test } from 'qunit'; | ||
|
||
import { setupTest } from 'ember-qunit'; | ||
|
||
import Model, { attr, belongsTo } from '@ember-data/model'; | ||
import { graphFor } from '@ember-data/record-data/-private'; | ||
import Store, { recordIdentifierFor } from '@ember-data/store'; | ||
|
||
module('Integration | Graph | Implicit Keys', function (hooks) { | ||
setupTest(hooks); | ||
|
||
hooks.beforeEach(function () { | ||
const { owner } = this; | ||
owner.register('service:store', Store); | ||
}); | ||
|
||
test('Non-polymorphic records do not trigger polymorphic assertions when they share the same key with another record', async function (assert) { | ||
const { owner } = this; | ||
class User extends Model { | ||
@attr name; | ||
@belongsTo('organization', { async: false, inverse: null }) organization; | ||
} | ||
class Product extends Model { | ||
@attr name; | ||
@belongsTo('organization', { async: false, inverse: null }) organization; | ||
} | ||
class Organization extends Model { | ||
@attr name; | ||
} | ||
owner.register('model:user', User); | ||
owner.register('model:product', Product); | ||
owner.register('model:organization', Organization); | ||
|
||
const store = owner.lookup('service:store'); | ||
const graph = graphFor(store); | ||
let user, product, organization; | ||
|
||
assert.expectNoAssertion(() => { | ||
[user, product, organization] = store.push({ | ||
data: [ | ||
{ | ||
type: 'user', | ||
id: '1', | ||
attributes: { name: 'Chris' }, | ||
relationships: { | ||
organization: { data: { type: 'organization', id: '1 ' } }, | ||
}, | ||
}, | ||
{ | ||
type: 'product', | ||
id: '1', | ||
attributes: { name: 'Awesome Relationships' }, | ||
relationships: { | ||
organization: { data: { type: 'organization', id: '1 ' } }, | ||
}, | ||
}, | ||
{ | ||
type: 'organization', | ||
id: '1', | ||
attributes: { name: 'Ember.js' }, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
const userIdentifier = recordIdentifierFor(user); | ||
const productIdentifier = recordIdentifierFor(product); | ||
const organizationIdentifier = recordIdentifierFor(organization); | ||
|
||
const userOrg = graph.get(userIdentifier, 'organization'); | ||
const userImpl = graph.get(organizationIdentifier, userOrg.definition.inverseKey); | ||
const productOrg = graph.get(productIdentifier, 'organization'); | ||
const productImpl = graph.get(organizationIdentifier, productOrg.definition.inverseKey); | ||
|
||
assert.notStrictEqual(userImpl, productImpl, 'We have separate implicit caches'); | ||
}); | ||
}); |