[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)
)
)
)
),
})
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?
1 Reply
nidomiro
nidomiroOP3mo ago
Ok I fixed it myself just after asking the question. I was on the right track. I needed to replace the line eq(schema.SisuBoard.id, schema.SisuBoardMembers.boardId), with eq(board.id, schema.SisuBoardMembers.boardId),
Want results from more Discord servers?
Add your server