Skip to content

Commit

Permalink
serialize to relative url only when id does not exist
Browse files Browse the repository at this point in the history
set null only when card.id does not exist
  • Loading branch information
tintinthong committed Feb 17, 2025
1 parent 58676fa commit 8ad51f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/base/card-api.gts
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,12 @@ class Contains<CardT extends FieldDefConstructor> implements Field<CardT, any> {
serialize(
value: InstanceType<CardT>,
doc: JSONAPISingleResourceDocument,
_visited: Set<string>,
opts?: SerializeOpts,
): JSONAPIResource {
let serialized: JSONAPISingleResourceDocument['data'] & {
meta: Record<string, any>;
} = callSerializeHook(this.card, value, doc);
} = callSerializeHook(this.card, value, doc, undefined, opts);
if (primitive in this.card) {
return { attributes: { [this.name]: serialized } };
} else {
Expand Down
3 changes: 2 additions & 1 deletion packages/host/app/services/card-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ export default class CardService extends Service {
// for a brand new card that has no id yet, we don't know what we are
// relativeTo because its up to the realm server to assign us an ID, so
// URL's should be absolute
maybeRelativeURL: null, // forces URL's to be absolute.
maybeRelativeURL: card.id ? undefined : null, // forces URL's to be absolute when no ID
});

// send doc over the wire with absolute URL's. The realm server will convert
// to relative URL's as it serializes the cards
let realmURL = await this.getRealmURL(card);
Expand Down

0 comments on commit 8ad51f6

Please sign in to comment.