Skip to content

Commit

Permalink
fix: local api update many respects limit
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens committed Oct 14, 2024
1 parent e3957d7 commit 3a43152
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/payload/src/collections/operations/local/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type BaseOptions<TSlug extends CollectionSlug> = {

export type ByIDOptions<TSlug extends CollectionSlug> = {
id: number | string
limit?: never
where?: never
} & BaseOptions<TSlug>

Expand Down Expand Up @@ -78,6 +79,7 @@ async function updateLocal<TSlug extends CollectionSlug>(
draft,
file,
filePath,
limit,
overrideAccess = true,
overrideLock,
overwriteExistingFiles = false,
Expand Down Expand Up @@ -105,6 +107,7 @@ async function updateLocal<TSlug extends CollectionSlug>(
depth,
disableTransaction,
draft,
limit,
overrideAccess,
overrideLock,
overwriteExistingFiles,
Expand Down
39 changes: 39 additions & 0 deletions test/database/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,45 @@ describe('database', () => {
})
})

describe('local API', () => {
it('should support `limit` arg in bulk updates', async () => {
for (let i = 0; i < 10; i++) {
await payload.create({
collection,
data: {
title: 'hello',
},
})
}

const updateResult = await payload.update({
collection,
data: {
title: 'world',
},
where: {
title: { equals: 'hello' },
},
limit: 5,
})

const findResult = await payload.find({
collection,
where: {
title: { exists: true },
},
})

const helloDocs = findResult.docs.filter((doc) => doc.title === 'hello')
const worldDocs = findResult.docs.filter((doc) => doc.title === 'world')

expect(updateResult.docs).toHaveLength(5)
expect(updateResult.docs[0].title).toStrictEqual('world')
expect(helloDocs).toHaveLength(5)
expect(worldDocs).toHaveLength(5)
})
})

describe('defaultValue', () => {
it('should set default value from db.create', async () => {
// call the db adapter create directly to bypass Payload's default value assignment
Expand Down

0 comments on commit 3a43152

Please sign in to comment.