diff --git a/src/db/Model.ts b/src/db/Model.ts index 70dc4f0..148fbf2 100644 --- a/src/db/Model.ts +++ b/src/db/Model.ts @@ -184,6 +184,12 @@ export default abstract class Model { this._cached_exists = false; } + public async validate(onlyFormat: boolean = false, connection?: Connection): Promise { + return await Promise.all(this._properties.map( + prop => this._validators[prop]?.execute(prop, this[prop], onlyFormat, connection) + )); + } + public async exists(): Promise { if (this._cached_exists === undefined) { const query = this._factory.select('1'); @@ -196,10 +202,11 @@ export default abstract class Model { return this._cached_exists; } - public async validate(onlyFormat: boolean = false, connection?: Connection): Promise { - return await Promise.all(this._properties.map( - prop => this._validators[prop]?.execute(prop, this[prop], onlyFormat, connection) - )); + public equals(model: this): boolean { + for (const field of this._factory.getPrimaryKeyFields()) { + if (this[field] !== model[field]) return false; + } + return true; } public get table(): string {