Order By Relational Data

I'm testing out the new relations API and have a slight issue but I'm not sure if this is a limitation of the querying API or if I'm just missing something. The scenerio is that I have 2 tables with a one-to-one relationship between them on a column. For instance:
Users:
id - PK
name - String
role_id - int (with one-to-one on a role)

Roles:
id - PK
name - String
Users:
id - PK
name - String
role_id - int (with one-to-one on a role)

Roles:
id - PK
name - String
I want to be able to order the users by their role name. How I imagined using it would be the following:
await db.query.users.findMany({
with: {
role: true,
},
orderBy: {
role: {
name: "asc",
}
},
});
await db.query.users.findMany({
with: {
role: true,
},
orderBy: {
role: {
name: "asc",
}
},
});
Is this possible with the new relational API?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?