ManyModelRelation: add cloneReduceToOne method

This commit is contained in:
Alice Gaudon 2020-06-27 14:58:39 +02:00
parent b70e5c0a21
commit 10257b8294
3 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wms-core",
"version": "0.10.1",
"version": "0.10.2",
"description": "Node web framework",
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
"author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -22,7 +22,7 @@ export default class User extends Model {
foreignKey: 'user_id'
});
public readonly mainEmail = this.emails.clone().constraint(q => q.where('main', true));
public readonly mainEmail = this.emails.cloneReduceToOne().constraint(q => q.where('main', true));
protected init(): void {
this.addProperty<string>('name', new Validator().acceptUndefined().between(3, 64));

View File

@ -86,6 +86,10 @@ export class ManyModelRelation<S extends Model, O extends Model> extends ModelRe
return new ManyModelRelation<S, O>(this.model, this.foreignModelClass, this.dbProperties);
}
public cloneReduceToOne(): OneModelRelation<S, O> {
return new OneModelRelation<S, O>(this.model, this.foreignModelClass, this.dbProperties);
}
public getModelID(): any {
return this.model[this.dbProperties.localKey];
}