drizzle-orm
drizzle-orm copied to clipboard
[BUG]: Relational query on sqlite/d1 with order-by has issues
What version of drizzle-orm are you using?
0.26.0
What version of drizzle-kit are you using?
No response
Describe the Bug
I debugged around for hours but those two queries are almost identical (the difference is that users: true is the first key vs messages:{...} being the first key the other time. This shouldn't be an issue and it is indeed working on a local d1 dev setup but it's not working on the the real remote d1. It just yields an unsorted messages array instead:
const chatNonSortedMessages = await db.query.chats.findFirst({
where: and(eq(chats.id, chatId), eq(chats.userId, userId)),
with: {
user: true,
messages: {
orderBy: desc(chatMessages.createdAt),
limit: 18
},
adventure: true
}
});
const chatSortedMessages = await db.query.chats.findFirst({
where: and(eq(chats.id, chatId), eq(chats.userId, userId)),
with: {
messages: {
orderBy: desc(chatMessages.createdAt),
limit: 18
},
adventure: true,
user: true,
}
});
Expected behavior
Both should yield the same result since it's not an array where order should matter.
Environment & setup
No response