1 year ago

#295367

test-img

Michael Hua

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!

node.js

database

express

objection.js

0 Answers

Your Answer

Accepted video resources