'Why objection instance method did not work

I have setup the Objection model for Company, if I use static method to query database it is OK. (I already have Model.knex(knex) before to setup everything.)

const companyInfo = await Company.query().findById(1)

But if I create company instance and then use instance method, get error - one of the identifier columns [id] is null or undefined. Even I add idColumn in model still got this error, seems not really relevant.

const company = new Company()
const companyInfo = await company.$query().findById(1)

Why I need use this way because I want to use Dependency Injection to inject model instance into my service. Does anyone know why this instance based way does not work? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source