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;
|
||||
}
|
||||
|
||||
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> {
|
||||
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<void[]> {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user