Is it possible to return has many relationship load to return a single object instead of an array.

db.query.products.findMany({
orderBy: (model, { desc }) => desc(model.createdAt),
with: {
discounts: {
where: (model, { eq }) =>
eq(model.organizationId, session.organizationId),
limit: 1,
},
},
}),
db.query.products.findMany({
orderBy: (model, { desc }) => desc(model.createdAt),
with: {
discounts: {
where: (model, { eq }) =>
eq(model.organizationId, session.organizationId),
limit: 1,
},
},
}),
output
[
{
id: 1,
discounts: [ [Object] ]
}
]
[
{
id: 1,
discounts: [ [Object] ]
}
]
desired output
[
{
id: 1,
discounts: Object
}
]
[
{
id: 1,
discounts: Object
}
]
1 Reply
rphlmr âš¡
rphlmr ⚡•5mo ago
Sadly, that's not possible. A V2 is planned but I am not sure this behaviour will change: https://github.com/drizzle-team/drizzle-orm/discussions/2316
GitHub
Relational API v2 · drizzle-team drizzle-orm · Discussion #2316
We've launched Drizzle Relational Queries exactly a year ago and it's time to ship a fundamental upgrade. We've gathered a massive amount of valuable feedback from the community and goi...
Want results from more Discord servers?
Add your server