How to check if QueryBuilder already has a specified relation in Objectionjs

16 Views Asked by At

I have an ObjectionJS query that is built dynamically based on a bunch of conditionals passed in.

For example this is the base query

const qb = Job.query(trx).select(id);

then there is are steps like so

if(body.sort)
 qb
 .leftJoinRelated('client')
 .orderBy(client name...)

if(body.filter)
 qb
 .leftJoinRelated('client')
 .whereIn('clientGuid', body.filter)

So when I execute my query pretty much I get an error that reads

table name "client" specified more than once

I am trying to see if there is a clean way for me to check which relations are already added to the query builder instance so that I don't attempt to add them again.

0

There are 0 best solutions below