Objection.js: Syntax question: self reference relation with other relations?

Created on 25 Mar 2021  路  1Comment  路  Source: Vincit/objection.js

  • Model Category belongs to one Category (self-reference)
  • Model Category has many Product

How can I write something like this (with products data loaded for each category level):

Category.query().withGraphFetched('[children.^, products]')

Most helpful comment

There's no way to do that using string expressions but maybe this works:

const expr = {
  products: true,
}

expr.children = expr

Category.query().withGraphFetched(expr)

>All comments

There's no way to do that using string expressions but maybe this works:

const expr = {
  products: true,
}

expr.children = expr

Category.query().withGraphFetched(expr)
Was this page helpful?
0 / 5 - 0 ratings