You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
import{Model}from'mongorito';exportclassUserextendsModel{configure(){this.before('create','checkIfExists');}asynccheckIfExists(){letexists=true;awaitUser.find({name: this.get('name')}).then(res=>exists=!!res.length);if(exists)thrownewError('User already exists on the database');}}exportclassCharacterextendsModel{asyncconfigure(){awaitUser.findOne({_id: this.get('owner')}).then(res=>this.set('owner',res));this.before('create','checkIfExists');}asynccheckIfExists(){letexists=true;awaitCharacter.find({owner: this.get('owner')}).then(res=>exists=!!res.length);if(exists)thrownewError('Character already exists on the database');}}
and want to save documents like this:
constchar=newCharacter({name: "Tobias",owner: "587fab63213d494a6b865547"// an ID for an existing User on DB});
Am I getting something wrong here?
I didn't understood how to get the Mode.populate() thing to work with this models neither.
The text was updated successfully, but these errors were encountered:
Basically instead of doing .get ('field') you'd do await char.model ('owner'),
The major issue is the need to register all models beforehand, else mongorito has no idea which class the sub-document references. However I think @vadimdemedes has added this to the roadmap.
I have the models below:
and want to save documents like this:
Am I getting something wrong here?
I didn't understood how to get the
Mode.populate()
thing to work with this models neither.The text was updated successfully, but these errors were encountered: