[SOLVED] invalid reference to FROM-clause entry for table

Hi all,

I'm trying to fetch data with some joins from a postgres db.

My query looks like this:
db.query.SisuBoard.findFirst({
    with: { categories: { with: { entries: { with: { owner: true } } } } },
    // eslint-disable-next-line @typescript-eslint/no-shadow
    where: (board, { eq, and, exists }) =>
      and(
        eq(board.id, boardId),
        exists(
          db
            .select()
            .from(schema.SisuBoardMembers)
            .where(
              and(
                eq(schema.SisuBoard.id, schema.SisuBoardMembers.boardId),
                eq(schema.SisuBoardMembers.memberId, userId)
              )
            )
        )
      ),
  })


But I always get the error invalid reference to FROM-clause entry for table "sisu_board". If I remove the complete exists check the error disappears, but I need that check.

What am I doing wrong?
Was this page helpful?