fix: allow use of an attribute named relationships

This commit is contained in:
Sami Mazouz 2024-10-25 15:50:36 +01:00
parent 53ac644516
commit 1ead69e9b6
No known key found for this signature in database
2 changed files with 5 additions and 2 deletions

View File

@ -671,7 +671,7 @@ export default class Application {
* @protected
*/
protected requestWasCrossOrigin(error: RequestError): boolean {
return new URL(error.options.url, document.baseURI).origin !== window.location.origin;
return new URL(error.options?.url, document.baseURI).origin !== window.location.origin;
}
protected requestErrorDefaultHandler(e: unknown, isDebug: boolean, formattedErrors: string[]): void {

View File

@ -192,7 +192,8 @@ export default abstract class Model {
// If a 'relationships' key exists, extract it from the attributes hash and
// set it on the top-level data object instead. We will be sending this data
// object to the API for persistence.
if (attributes.relationships) {
// But only if the model does not actually have a real relationships attribute.
if (attributes.relationships && !('relationships' in this)) {
data.relationships = {};
for (const key in attributes.relationships) {
@ -208,6 +209,8 @@ export default abstract class Model {
delete attributes.relationships;
}
console.log('data', data);
// Before we update the model's data, we should make a copy of the model's
// old data so that we can revert back to it if something goes awry during
// persistence.