Jaden
Jaden
DTDrizzle Team
Created by Jaden on 4/24/2025 in #help
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?
1 replies
DTDrizzle Team
Created by Jaden on 9/13/2024 in #help
Select All from Sub-query
Hi, I'm trying to figure out if it's possible for me to select all the columns from a sub-query. I imagine if it were possible it'd be something like this:
const subQuery = db().select({ ... }).from(...).as("subquery");

const query = db()
.select({ ...subQuery })
.from(subQuery);
const subQuery = db().select({ ... }).from(...).as("subquery");

const query = db()
.select({ ...subQuery })
.from(subQuery);
Do I have to name all the columns?
6 replies