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";
|
import {Request} from "express";
|
||||||
|
|
||||||
export default abstract class Model {
|
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 {
|
public static create<T extends Model>(this: Type<T>, data: any): T {
|
||||||
return ModelFactory.get(this).create(data);
|
return ModelFactory.get(this).create(data);
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,8 @@ export default class ModelFactory<T extends Model> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get table(): string {
|
public get table(): string {
|
||||||
return this.modelType.name
|
// @ts-ignore
|
||||||
.replace(/(?:^|\.?)([A-Z])/g, (x, y) => '_' + y.toLowerCase())
|
return this.modelType.table;
|
||||||
.replace(/^_/, '')
|
|
||||||
+ 's';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public select(...fields: string[]): ModelQuery<T> {
|
public select(...fields: string[]): ModelQuery<T> {
|
||||||
|
Loading…
Reference in New Issue
Block a user