From fd0bf21de765bb93403ae9e2b0d73140f5ad7d1c Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 15 Jul 2024 06:04:05 +0000 Subject: [PATCH] fix: clear single query cache when updating column which is referred a foreign key --- packages/nocodb/src/models/Column.ts | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index 56bf2212d7..10eccbda80 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -1264,6 +1264,42 @@ export default class Column implements ColumnType { logger.error(err); }); } + + // clear any related table cache if updating a FK column + { + // Get LTAR columns in which current column is referenced as foreign key + const ltarColumns = await ncMeta.metaList2( + context.workspace_id, + context.base_id, + MetaTable.COL_RELATIONS, + { + xcCondition: { + _and: [ + { + _or: [ + { fk_child_column_id: { eq: colId } }, + { fk_parent_column_id: { eq: colId } }, + { fk_mm_child_column_id: { eq: colId } }, + { fk_mm_parent_column_id: { eq: colId } }, + ], + }, + { + fk_related_model_id: { neq: oldCol.fk_model_id }, + }, + ], + }, + }, + ); + + for (const linkCol of ltarColumns) { + await View.clearSingleQueryCache( + context, + (linkCol.colOptions as LinksColumn).fk_related_model_id, + null, + ncMeta, + ); + } + } } static async updateAlias(