I'm trying to generate this postgres SQL with Knex and Objection:
select *
from "WorkoutEntry" e
where EXISTS (
select *
from "WorkoutCategory" c
INNER JOIN "StandardWorkoutDefinition" d on d."workoutCategoryId" = c.id
where c.id = 2 and e."standardWorkoutDefinitionId" = d.id
);
I'm almost there - but the StandardWorkoutDefinition.id
line is always converting to a literal string instead of referencing the proper column in the DB.
return await WorkoutEntry.query()
.whereExists(
WorkoutCategory.query()
.innerJoin(
'StandardWorkoutDefinition',
'StandardWorkoutDefinition.workoutCategoryId',
'WorkoutCategory.id',
)
.where('WorkoutCategory.id', workoutCategoryId)
.where(
'WorkoutEntry.standardWorkoutDefinitionId',
'StandardWorkoutDefinition.id',
),
)
.andWhere({
deletedAt: null,
memberId,
});
How can I get e."standardWorkoutDefinitionId" to output instead to make the query right?