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