0

I have this legacy code below using objection.js and I need to convert this to objection.js 3.

const result = await DeptClass.query()
  .select(['employeerClass.label', 'employeerClass.description', 'employeerClass.id'])
  .joinRelation('projectClasses')
  .where('projectClasses.id', req.params.id)
  .eager('depCodes(wccSelect).[state(stateSelect)]', {
    wccSelect,
    stateSelect
  })

In their documentation, lots of methods have renamed. http://vincit.github.io/objection.js/release-notes/changelog.html#_2-0-0

For example,
joinRelation -> joinRelated,
eager -> withGraphFetched

So I came up with this code:

const result = await DeptClass.query()
  .joinRelated('projectClasses')
  .select('employeerClass.label', 'employeerClass.description', 'employeerClass.id')
  .where('projectClasses.id', req.params.id)
  .withGraphFetched('depCodes(wccSelect).[state(stateSelect)]', {
    wccSelect,
    stateSelect
  })

However, when I run this code, the generated sql query is correct but there is NO RESULT and NO ERRORS found.

Any idea what's wrong with this code?

Arman Ortega
  • 3,003
  • 1
  • 30
  • 28

1 Answers1

0

Finally, I was able to solved this problem. In order to retrieve the data, need to add modifiers like this:

  .withGraphFetched('depCodes(wccSelect).[state(stateSelect)]')
  .modifiers({
    wccSelect,
    stateSelect
  }))
Arman Ortega
  • 3,003
  • 1
  • 30
  • 28