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

Viewed 347

Is it possible to retrieve (at least) the id of created model in $afterInsert hook in Objection ORM?

  async $afterInsert(queryContext) 

I guess and hope it could be available somehow from queryContext?

The goal is to be able to log this id when created in an allowed graph through insertGraph method.

1 Answers

You can access the returned data at this:

  async $afterInsert(queryContext) {
    await super.$afterInsert(queryContext);
    console.log(this.id)
  }

Related