Skip to content

Commit

Permalink
Fix bug: linksToMany field used wrong relative url when deserializing (
Browse files Browse the repository at this point in the history
  • Loading branch information
tintinthong authored Jan 7, 2025
1 parent 5e6fe5e commit d51147f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/base/card-api.gts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,17 +1297,22 @@ class LinksToMany<FieldT extends CardDefConstructor>
cachedInstance[isSavedInstance] = true;
return cachedInstance;
}
let resourceId = new URL(value.links.self, relativeTo).href;
let resourceId = new URL(
value.links.self,
!Array.isArray(doc.data) && 'id' in doc.data && doc.data.id
? doc.data.id
: relativeTo,
).href;
if (loadedValues && Array.isArray(loadedValues)) {
let loadedValue = loadedValues.find(
(v) => isCardOrField(v) && 'id' in v && v.id === resourceId,
);
if (loadedValue) {
return loadedValue;
}
}
let resource = resourceFrom(doc, resourceId);
if (!resource) {
if (loadedValues && Array.isArray(loadedValues)) {
let loadedValue = loadedValues.find(
(v) => isCardOrField(v) && 'id' in v && v.id === resourceId,
);
if (loadedValue) {
return loadedValue;
}
}
return {
type: 'not-loaded',
reference: value.links.self,
Expand Down

0 comments on commit d51147f

Please sign in to comment.