orderBy related table column

Given a relational query such as
const matchResult = await db.query.matches.findMany({
where: and(
between(matches.time, from, to),
),
orderBy: [
asc(matches.time),
],
with: {
team1: true, // one to one with a "team" entity
team2: true, // one to one with a "team" entity
},
});
const matchResult = await db.query.matches.findMany({
where: and(
between(matches.time, from, to),
),
orderBy: [
asc(matches.time),
],
with: {
team1: true, // one to one with a "team" entity
team2: true, // one to one with a "team" entity
},
});
how can I additionally order by a column from the team1 relation? (bear in mind that a limit and offset may be used, so I don't want to have to fetch all results then sort them after, as it defeats the point of using mysql for this task)
7 Replies
roacfe
roacfe16mo ago
hi! I am facing a similar issue, were you able to find a solution?
mr_pablo
mr_pabloOP15mo ago
I haven't yet @Andrew Sherman any ideas?
Andrii Sherman
Andrii Sherman15mo ago
so do you need to order macthes by team1 value?
mr_pablo
mr_pabloOP15mo ago
yea
Andrii Sherman
Andrii Sherman15mo ago
I think it's possible for now with current Relational API capabilities. But this part of Drizzle will be improving, so I guess eventually we will have it
mr_pablo
mr_pabloOP15mo ago
So I can't do it just yet? Or it just a documentation issue?
Andrii Sherman
Andrii Sherman15mo ago
can't do it yet
Want results from more Discord servers?
Add your server