From c962144cef2e7b63160480131657067952bdbf64 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 9 Nov 2021 15:55:45 +0100 Subject: [PATCH] Fix relation not having collection and field values (#9652) --- api/src/utils/apply-snapshot.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/api/src/utils/apply-snapshot.ts b/api/src/utils/apply-snapshot.ts index f482878505..b5380673aa 100644 --- a/api/src/utils/apply-snapshot.ts +++ b/api/src/utils/apply-snapshot.ts @@ -88,18 +88,20 @@ export async function applySnapshot( } const relationsService = new RelationsService({ knex: trx, schema: await getSchema({ database: trx }) }); - - for (const { collection, field, diff } of snapshotDiff.relations) { + for (const { collection, field, diff, related_collection } of snapshotDiff.relations) { if (diff?.[0].kind === 'N') { await relationsService.createOne((diff[0] as DiffNew).rhs); } if (diff?.[0].kind === 'E') { - const updates = diff.reduce((acc, edit) => { - if (edit.kind !== 'E') return acc; - set(acc, edit.path!, edit.rhs); - return acc; - }, {}); + const updates = diff.reduce( + (acc, edit) => { + if (edit.kind !== 'E') return acc; + set(acc, edit.path!, edit.rhs); + return acc; + }, + { collection, field, related_collection } + ); await relationsService.updateOne(collection, field, updates); }