Skip to content

Commit

Permalink
fix: allow use of an attribute named relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Oct 25, 2024
1 parent 53ac644 commit 1ead69e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion framework/core/js/src/common/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion framework/core/js/src/common/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Expand Down

0 comments on commit 1ead69e

Please sign in to comment.