diff --git a/packages/server/src/api/controllers/model.js b/packages/server/src/api/controllers/model.js index f8c5ebefd7..aa038bf96b 100644 --- a/packages/server/src/api/controllers/model.js +++ b/packages/server/src/api/controllers/model.js @@ -25,7 +25,7 @@ exports.save = async function(ctx) { ...ctx.request.body, } - // update renamed record fields when model is updated + // rename record fields when table column is renamed const { _rename } = modelToSave if (_rename) { const records = await db.query(`database/all_${modelToSave._id}`, { @@ -41,6 +41,15 @@ exports.save = async function(ctx) { delete modelToSave._rename } + // update schema of non-statistics views when new columns are added + for (let view in modelToSave.views) { + const modelView = modelToSave.views[view] + if (!modelView) continue + + if (modelView.schema.group || modelView.schema.field) continue + modelView.schema = modelToSave.schema + } + const result = await db.post(modelToSave) modelToSave._rev = result.rev diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index b5f9638115..497716f8e4 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -103,9 +103,10 @@ function viewTemplate({ field, modelId, groupBy, filters = [], calculation }) { let schema = null if (calculation) { - schema = groupBy - ? { ...GROUP_PROPERTY, ...SCHEMA_MAP[calculation] } - : { ...FIELD_PROPERTY, ...SCHEMA_MAP[calculation] } + schema = { + ...(groupBy ? GROUP_PROPERTY : FIELD_PROPERTY), + ...SCHEMA_MAP[calculation] + } } return {