From 78286ae514aafd7f5263ee3a7197818b5e35f2e5 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 25 Feb 2021 17:07:32 +0000 Subject: [PATCH] Minor update to fix an issue when updating a row that it would throw an error with 1->to->many relationships on existing relationships for that row, as well as cleaning up how relationshipType is put onto the linked table. --- .../src/db/linkedRows/LinkController.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/server/src/db/linkedRows/LinkController.js b/packages/server/src/db/linkedRows/LinkController.js index a5404709f2..2e86592b24 100644 --- a/packages/server/src/db/linkedRows/LinkController.js +++ b/packages/server/src/db/linkedRows/LinkController.js @@ -183,12 +183,14 @@ class LinkController { // iterate through the link IDs in the row field, see if any don't exist already for (let linkId of rowField) { if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) { - const links = await getLinkDocuments({ - appId: this._appId, - tableId: field.tableId, - rowId: linkId, - includeDocs: IncludeDocs.INCLUDE, - }) + const links = ( + await getLinkDocuments({ + appId: this._appId, + tableId: field.tableId, + rowId: linkId, + includeDocs: IncludeDocs.EXCLUDE, + }) + ).filter(link => link.id !== row._id) // The 1 side of 1:N is already related to something else // You must remove the existing relationship @@ -330,12 +332,7 @@ class LinkController { if (field.relationshipType) { // Ensure that the other side of the relationship is locked to one record linkConfig.relationshipType = field.relationshipType - - // Update this table to be the many - table.schema[field.name].relationshipType = - RelationshipTypes.MANY_TO_MANY - const response = await this._db.put(table) - table._rev = response.rev + delete field.relationshipType } // check the linked table to make sure we aren't overwriting an existing column