Refactor BaseModel and ModelPermission classes to improve column handling

This commit is contained in:
Simon Larsen 2024-04-29 14:15:11 +01:00
parent 83e207a7de
commit 6692fb00b8
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
2 changed files with 8 additions and 0 deletions

View File

@ -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 { public isEntityColumn(columnName: string): boolean {
const tableColumnType: TableColumnMetadata = getTableColumn( const tableColumnType: TableColumnMetadata = getTableColumn(
this, this,

View File

@ -649,6 +649,10 @@ export default class ModelPermission {
const relationSelect: RelationSelect<TBaseModel> = {}; const relationSelect: RelationSelect<TBaseModel> = {};
for (const key in select) { for (const key in select) {
if (!model.isTableColumn(key)) {
delete (select as JSONObject)[key];
}
if (model.isEntityColumn(key)) { if (model.isEntityColumn(key)) {
if (typeof (select as JSONObject)[key] === Typeof.Object) { if (typeof (select as JSONObject)[key] === Typeof.Object) {
(relationSelect as any)[key] = true; (relationSelect as any)[key] = true;