Model: add equals method
This commit is contained in:
parent
68ff977bcc
commit
74ffdf8325
@ -184,6 +184,12 @@ export default abstract class Model {
|
|||||||
this._cached_exists = false;
|
this._cached_exists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async validate(onlyFormat: boolean = false, connection?: Connection): Promise<void[]> {
|
||||||
|
return await Promise.all(this._properties.map(
|
||||||
|
prop => this._validators[prop]?.execute(prop, this[prop], onlyFormat, connection)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public async exists(): Promise<boolean> {
|
public async exists(): Promise<boolean> {
|
||||||
if (this._cached_exists === undefined) {
|
if (this._cached_exists === undefined) {
|
||||||
const query = this._factory.select('1');
|
const query = this._factory.select('1');
|
||||||
@ -196,10 +202,11 @@ export default abstract class Model {
|
|||||||
return this._cached_exists;
|
return this._cached_exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async validate(onlyFormat: boolean = false, connection?: Connection): Promise<void[]> {
|
public equals(model: this): boolean {
|
||||||
return await Promise.all(this._properties.map(
|
for (const field of this._factory.getPrimaryKeyFields()) {
|
||||||
prop => this._validators[prop]?.execute(prop, this[prop], onlyFormat, connection)
|
if (this[field] !== model[field]) return false;
|
||||||
));
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get table(): string {
|
public get table(): string {
|
||||||
|
Loading…
Reference in New Issue
Block a user