update view schema when table updated

This commit is contained in:
Martin McKeaveney 2020-09-14 15:40:45 +01:00
parent 618730fe21
commit 72e3070ad2
2 changed files with 14 additions and 4 deletions

View File

@ -25,7 +25,7 @@ exports.save = async function(ctx) {
...ctx.request.body, ...ctx.request.body,
} }
// update renamed record fields when model is updated // rename record fields when table column is renamed
const { _rename } = modelToSave const { _rename } = modelToSave
if (_rename) { if (_rename) {
const records = await db.query(`database/all_${modelToSave._id}`, { const records = await db.query(`database/all_${modelToSave._id}`, {
@ -41,6 +41,15 @@ exports.save = async function(ctx) {
delete modelToSave._rename 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) const result = await db.post(modelToSave)
modelToSave._rev = result.rev modelToSave._rev = result.rev

View File

@ -103,9 +103,10 @@ function viewTemplate({ field, modelId, groupBy, filters = [], calculation }) {
let schema = null let schema = null
if (calculation) { if (calculation) {
schema = groupBy schema = {
? { ...GROUP_PROPERTY, ...SCHEMA_MAP[calculation] } ...(groupBy ? GROUP_PROPERTY : FIELD_PROPERTY),
: { ...FIELD_PROPERTY, ...SCHEMA_MAP[calculation] } ...SCHEMA_MAP[calculation]
}
} }
return { return {