Leftjoin works but With doesn’t

Good Morning, I am having an issue with understanding why my query isn’t working
Db.query.matches.findMany({
Where: lt(match.deadline, now),
With: { proofSubmissions: true }
})
Db.query.matches.findMany({
Where: lt(match.deadline, now),
With: { proofSubmissions: true }
})
This does not return both matches and related proof submission but running the same query with leftjoin show below works properly
db
.select()
.from(matches)
.leftJoin(proofSubmissions, eq(matches.match_id, proofSubmissions.match_id))
.where(
and(
lt(matches.submission_deadline, new Date()),
)
);

db
.select()
.from(matches)
.leftJoin(proofSubmissions, eq(matches.match_id, proofSubmissions.match_id))
.where(
and(
lt(matches.submission_deadline, new Date()),
)
);

I also tried specifying the columns I wanted returned using the with clause and still didn’t work, not sure what I’m missing, this is the first time using drizzle
1 Reply
Captainrobb
CaptainrobbOP2mo ago
but it does work properly here, so i must be doing something weong with the other one
const player = db.query.players.findFirst({
where: eq(players.player_id, payout.playerId),
with: { user: true },
});
const player = db.query.players.findFirst({
where: eq(players.player_id, payout.playerId),
with: { user: true },
});
If anyone finds this I figured it out. I had a relations and inverse relations set up in my relations.ts file and by combining them into a single relations function it fixed the issue

Did you find this page helpful?