diff --git a/src/db/Model.ts b/src/db/Model.ts index 7843ab2..25d3993 100644 --- a/src/db/Model.ts +++ b/src/db/Model.ts @@ -9,6 +9,13 @@ import ModelQuery, {ModelQueryResult} from "./ModelQuery"; import {Request} from "express"; export default abstract class Model { + public static get table(): string { + return this.name + .replace(/(?:^|\.?)([A-Z])/g, (x, y) => '_' + y.toLowerCase()) + .replace(/^_/, '') + + 's'; + } + public static create(this: Type, data: any): T { return ModelFactory.get(this).create(data); } diff --git a/src/db/ModelFactory.ts b/src/db/ModelFactory.ts index 39b1216..1bfcd94 100644 --- a/src/db/ModelFactory.ts +++ b/src/db/ModelFactory.ts @@ -39,10 +39,8 @@ export default class ModelFactory { } public get table(): string { - return this.modelType.name - .replace(/(?:^|\.?)([A-Z])/g, (x, y) => '_' + y.toLowerCase()) - .replace(/^_/, '') - + 's'; + // @ts-ignore + return this.modelType.table; } public select(...fields: string[]): ModelQuery {