Back to Objection Js

Joins

doc/recipes/joins.md

3.1.5601 B
Original Source

Joins

Again, do as you would with a knex query builder:

js
const people = await Person.query()
  .select('persons.*', 'parent.firstName as parentName')
  .join('persons as parent', 'persons.parentId', 'parent.id');

console.log(people[0].parentName);

Objection also has helpers like the joinRelated method family:

js
const people = await Person.query()
  .select('parent:parent.name as grandParentName')
  .joinRelated('parent.parent');

console.log(people[0].grandParentName);