I want the $beforeValidate to wait for the async operation to complete as it updates the object to make it pass validation. But currently the $beforeValidate completes and rejects the record as it is not waiting for the async operation to complete.
class Label extends Model {
async $beforeValidate() {
if(this.name === undefined){
const res = await axios.get('/getSomeName')
console.log(res.body)
this.name = res.body
}
}
static get jsonSchema () {
return {
type: 'object',
required: ['name'],
properties: {
id: { type: 'integer' },
name: { type: 'string' }
}
}
}
}
Now when i insert a label with name undefined I can see that the validation error is raised before the async API call has even finished
await Label.query().insert({name: undefined})