update view schema when table updated
This commit is contained in:
parent
618730fe21
commit
72e3070ad2
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue