From 2aa6abfd95ad0c26c7f0302f574f136c000e9b66 Mon Sep 17 00:00:00 2001 From: "Brian J. Geiger" Date: Tue, 8 Aug 2023 14:25:18 -0400 Subject: [PATCH] Remove most non-dirty relationships (#1918) ## Purpose When upgrading to ember 3.28, we lost the ability to distinguish between dirty relationships and clean ones when PATCHing a record, so we would send all the relationships. This was a problem because many of the clean relationships in the serializer had null information, which broke the API, because it doesn't like PATCHed relationships with null information. This fixes that by removing any relationship that is just null info in the serializer. We will still sometimes PATCH relationships we don't need to, but the info should be the same and thus not cause problems for the API. ## Summary of Changes 1. Scan for null relationships in osf-serializer and remove them from the request payload. --- app/serializers/osf-serializer.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/serializers/osf-serializer.ts b/app/serializers/osf-serializer.ts index 46eccd6065..6fc3525e24 100644 --- a/app/serializers/osf-serializer.ts +++ b/app/serializers/osf-serializer.ts @@ -147,6 +147,14 @@ export default class OsfSerializer extends JSONAPISerializer { delete serialized.data.attributes![attribute]; } } + if (serialized.data.relationships) { + for (const key of Object.keys(serialized.data.relationships)) { + const rel = serialized.data.relationships[key]; + if (rel === null) { + delete serialized.data.relationships[key]; + } + } + } } return serialized;