From 6692fb00b865406577dcde16de1810dd0536f924 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 29 Apr 2024 14:15:11 +0100 Subject: [PATCH] Refactor BaseModel and ModelPermission classes to improve column handling --- Common/Models/BaseModel.ts | 4 ++++ CommonServer/Types/Database/ModelPermission.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Common/Models/BaseModel.ts b/Common/Models/BaseModel.ts index 46fa08c68d..91d76f9651 100644 --- a/Common/Models/BaseModel.ts +++ b/Common/Models/BaseModel.ts @@ -371,6 +371,10 @@ export default class BaseModel extends BaseEntity { } } + public isTableColumn(columnName: string): boolean { + return Boolean(getTableColumn(this, columnName)); + } + public isEntityColumn(columnName: string): boolean { const tableColumnType: TableColumnMetadata = getTableColumn( this, diff --git a/CommonServer/Types/Database/ModelPermission.ts b/CommonServer/Types/Database/ModelPermission.ts index 5303b68438..bcc6db55ab 100644 --- a/CommonServer/Types/Database/ModelPermission.ts +++ b/CommonServer/Types/Database/ModelPermission.ts @@ -649,6 +649,10 @@ export default class ModelPermission { const relationSelect: RelationSelect = {}; for (const key in select) { + if (!model.isTableColumn(key)) { + delete (select as JSONObject)[key]; + } + if (model.isEntityColumn(key)) { if (typeof (select as JSONObject)[key] === Typeof.Object) { (relationSelect as any)[key] = true;