-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove type check that prevents polymorphic types in API responses #7421
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,48 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function(hooks) | |
assert.equal(posts.get('firstObject.title'), 'Ember.js rocks', 'Sets correct title to record'); | ||
}); | ||
|
||
test('find many polymorphic records', async function(assert) { | ||
assert.expect(4); | ||
|
||
ajaxResponse([ | ||
{ | ||
data: [ | ||
{ | ||
type: 'github-handles', | ||
id: '1', | ||
attributes: { | ||
username: 'ykatz', | ||
}, | ||
}, | ||
{ | ||
type: 'twitter-handles', | ||
id: '2', | ||
attributes: { | ||
nickname: 'ykatz', | ||
}, | ||
}, | ||
], | ||
included: [], | ||
}, | ||
]); | ||
|
||
let handles = await store.findAll('handle'); | ||
|
||
let twitter_handles = store.peekAll('twitter-handles'); | ||
let github_handles = store.peekAll('github-handles'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be singular |
||
|
||
//This should work b/c we loaded these types from the API, but it doesn't | ||
assert.equal(twitter_handles.get('length'), 1); | ||
assert.equal(github_handles.get('length'), 1); | ||
|
||
assert.equal(passedUrl[0], '/handles', 'Builds correct URL'); | ||
|
||
//These won't work because we didn't load anything of the base type 'handles' | ||
assert.equal(handles.get('length'), 2, 'Returns the correct number of records'); | ||
assert.equal(handles.get('firstObject.username'), 'ykatz', 'Sets correct username to record'); | ||
assert.equal(handles.get('secondObject.nickname'), 'ykatz', 'Sets correct username to record'); | ||
}); | ||
|
||
test('queryRecord - primary data being a single record', async function(assert) { | ||
ajaxResponse([ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,7 +496,6 @@ function performRecordIdentifierUpdate( | |
updateFn: UpdateMethod | ||
) { | ||
let { id, lid } = data; | ||
let type = data.type && normalizeModelName(data.type); | ||
|
||
if (DEBUG) { | ||
// get the mutable instance behind our proxy wrapper | ||
|
@@ -526,13 +525,6 @@ function performRecordIdentifierUpdate( | |
} | ||
} | ||
|
||
// TODO consider just ignoring here to allow flexible polymorphic support | ||
if (type && type !== identifier.type) { | ||
throw new Error( | ||
`The 'type' for a RecordIdentifier cannot be updated once it has been set. Attempted to set type for '${wrapper}' to '${type}'.` | ||
); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @ryandoherty! Do you have a test addition we can verify this results in added behaviour? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not, I can give it a whirl. First time working on anything Ember, happy to take pointers to where/how I should do this. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd note that we do have tests for single-table polymorphism support in place already. We might be able to improve our default implementation but the intent with identifiers is that you'll configure the cache in your own app to handle edge cases around one record having multiple potential identities. |
||
updateFn(wrapper, data, 'record'); | ||
} else { | ||
updateFn(identifier, data, 'record'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be singular too, though this may not matter for the test