Cursor based paging issue for multilevel relationships

I have this query. As you can see my paging field's like cursors are inside the select: works section. Question completes in the next post.
const works = await this.#client.follow.findMany({
select: {
followed: {
select: {
works: {
take: pageSize,
skip: lastCursor ? 1 : 0,
cursor: lastCursor
? {
id: lastCursor,
}
: undefined,
orderBy: {
id: SortOrder.Desc,
},
select: {
id: true,
updatedAt: true,
title: true,
description: true,
content: true,
authorId: true,
author: {
select: {
userName: true,
fullName: true,
description: true,
},
},
workTopics: {
select: {
topic: {
select: {
id: true,
name: true,
},
},
},
},
workLikes: {
select: {
id: true,
},
},
},
},
},
},
},
where: {
followerId,
},
});
const works = await this.#client.follow.findMany({
select: {
followed: {
select: {
works: {
take: pageSize,
skip: lastCursor ? 1 : 0,
cursor: lastCursor
? {
id: lastCursor,
}
: undefined,
orderBy: {
id: SortOrder.Desc,
},
select: {
id: true,
updatedAt: true,
title: true,
description: true,
content: true,
authorId: true,
author: {
select: {
userName: true,
fullName: true,
description: true,
},
},
workTopics: {
select: {
topic: {
select: {
id: true,
name: true,
},
},
},
},
workLikes: {
select: {
id: true,
},
},
},
},
},
},
},
where: {
followerId,
},
});
1 Reply
jsoneaday
jsoneaday2mo ago
When I first run this query with parameters pageSize = 5 and no lastCursor it returns expected data like this. However the second run returns nothing. My sort is descending so shouldn't id values less than 300n be returned?
works before flatmap: [
257n, 256n, 255n, 254n, 253n, 263n,
262n, 261n, 259n, 258n, 268n, 267n,
266n, 265n, 264n, 273n, 272n, 271n,
270n, 269n, 278n, 277n, 276n, 275n,
274n, 284n, 283n, 282n, 281n, 279n,
289n, 288n, 287n, 286n, 285n, 294n,
293n, 292n, 291n, 290n, 299n, 298n,
297n, 296n, 295n, 304n, 303n, 302n,
301n, 300n
]
firstFive: [ 304n, 303n, 302n, 301n, 300n ]
lastCursor: 300n
works before flatmap: []
nextFive: []
works before flatmap: [
257n, 256n, 255n, 254n, 253n, 263n,
262n, 261n, 259n, 258n, 268n, 267n,
266n, 265n, 264n, 273n, 272n, 271n,
270n, 269n, 278n, 277n, 276n, 275n,
274n, 284n, 283n, 282n, 281n, 279n,
289n, 288n, 287n, 286n, 285n, 294n,
293n, 292n, 291n, 290n, 299n, 298n,
297n, 296n, 295n, 304n, 303n, 302n,
301n, 300n
]
firstFive: [ 304n, 303n, 302n, 301n, 300n ]
lastCursor: 300n
works before flatmap: []
nextFive: []
Want results from more Discord servers?
Add your server