From ee10e6a165afeb108070c21bf5968fff29635974 Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Thu, 1 Oct 2020 11:49:49 +0100 Subject: [PATCH] Adding validation so that a linked column and a primary display column cannot be renamed. --- packages/server/src/api/controllers/model.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/model.js b/packages/server/src/api/controllers/model.js index b046a2f3a8..df6c794109 100644 --- a/packages/server/src/api/controllers/model.js +++ b/packages/server/src/api/controllers/model.js @@ -34,7 +34,11 @@ exports.save = async function(ctx) { // rename record fields when table column is renamed const { _rename } = modelToSave - if (_rename) { + if (_rename && modelToSave.schema[_rename.updated].type === "link") { + throw "Cannot rename a linked field." + } else if (_rename && modelToSave.primaryDisplay === _rename.old) { + throw "Cannot rename the primary display field." + } else if (_rename) { const records = await db.query(`database/all_${modelToSave._id}`, { include_docs: true, })