ManyModelRelation: add cloneReduceToOne method
This commit is contained in:
parent
b70e5c0a21
commit
10257b8294
@ -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>",
|
||||
|
@ -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));
|
||||
|
@ -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];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user