检索在 Objection ORM 中的 $afterInsert 挂钩中创建的模型的 ID

Retrieve id of model created in $afterInsert hook in Objection ORM

是否可以(至少)在 Objection ORM 的 $afterInsert 挂钩中检索创建模型的 ID?

  async $afterInsert(queryContext) 

我想并希望它能以某种方式从 queryContext 中获得?

目标是在通过 insertGraph 方法在允许的图形中创建时能够记录此 ID。

您可以在 this:

访问返回的数据
  async $afterInsert(queryContext) {
    await super.$afterInsert(queryContext);
    console.log(this.id)
  }