Skip to content

Commit 3110c1b

Browse files
authored
fix: local update limit (#8704)
1 parent f1ebf56 commit 3110c1b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/payload/src/collections/operations/local/update.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type BaseOptions<TSlug extends CollectionSlug> = {
4141

4242
export type ByIDOptions<TSlug extends CollectionSlug> = {
4343
id: number | string
44+
limit?: never
4445
where?: never
4546
} & BaseOptions<TSlug>
4647

@@ -78,6 +79,7 @@ async function updateLocal<TSlug extends CollectionSlug>(
7879
draft,
7980
file,
8081
filePath,
82+
limit,
8183
overrideAccess = true,
8284
overrideLock,
8385
overwriteExistingFiles = false,
@@ -105,6 +107,7 @@ async function updateLocal<TSlug extends CollectionSlug>(
105107
depth,
106108
disableTransaction,
107109
draft,
110+
limit,
108111
overrideAccess,
109112
overrideLock,
110113
overwriteExistingFiles,

test/database/int.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,45 @@ describe('database', () => {
501501
})
502502
})
503503

504+
describe('local API', () => {
505+
it('should support `limit` arg in bulk updates', async () => {
506+
for (let i = 0; i < 10; i++) {
507+
await payload.create({
508+
collection,
509+
data: {
510+
title: 'hello',
511+
},
512+
})
513+
}
514+
515+
const updateResult = await payload.update({
516+
collection,
517+
data: {
518+
title: 'world',
519+
},
520+
where: {
521+
title: { equals: 'hello' },
522+
},
523+
limit: 5,
524+
})
525+
526+
const findResult = await payload.find({
527+
collection,
528+
where: {
529+
title: { exists: true },
530+
},
531+
})
532+
533+
const helloDocs = findResult.docs.filter((doc) => doc.title === 'hello')
534+
const worldDocs = findResult.docs.filter((doc) => doc.title === 'world')
535+
536+
expect(updateResult.docs).toHaveLength(5)
537+
expect(updateResult.docs[0].title).toStrictEqual('world')
538+
expect(helloDocs).toHaveLength(5)
539+
expect(worldDocs).toHaveLength(5)
540+
})
541+
})
542+
504543
describe('defaultValue', () => {
505544
it('should set default value from db.create', async () => {
506545
// call the db adapter create directly to bypass Payload's default value assignment

0 commit comments

Comments
 (0)