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
        },
      });


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)
Was this page helpful?