Move responsability of table field from ModelFactory to Model (static)
This commit is contained in:
parent
be6e659ca2
commit
5ca1ddef43
@ -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<T extends Model>(this: Type<T>, data: any): T {
|
||||
return ModelFactory.get(this).create(data);
|
||||
}
|
||||
|
@ -39,10 +39,8 @@ export default class ModelFactory<T extends Model> {
|
||||
}
|
||||
|
||||
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<T> {
|
||||
|
Loading…
Reference in New Issue
Block a user