File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
packages/payload/src/collections/operations/local Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ export type BaseOptions<TSlug extends CollectionSlug> = {
41
41
42
42
export type ByIDOptions < TSlug extends CollectionSlug > = {
43
43
id : number | string
44
+ limit ?: never
44
45
where ?: never
45
46
} & BaseOptions < TSlug >
46
47
@@ -78,6 +79,7 @@ async function updateLocal<TSlug extends CollectionSlug>(
78
79
draft,
79
80
file,
80
81
filePath,
82
+ limit,
81
83
overrideAccess = true ,
82
84
overrideLock,
83
85
overwriteExistingFiles = false ,
@@ -105,6 +107,7 @@ async function updateLocal<TSlug extends CollectionSlug>(
105
107
depth,
106
108
disableTransaction,
107
109
draft,
110
+ limit,
108
111
overrideAccess,
109
112
overrideLock,
110
113
overwriteExistingFiles,
Original file line number Diff line number Diff line change @@ -501,6 +501,45 @@ describe('database', () => {
501
501
} )
502
502
} )
503
503
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
+
504
543
describe ( 'defaultValue' , ( ) => {
505
544
it ( 'should set default value from db.create' , async ( ) => {
506
545
// call the db adapter create directly to bypass Payload's default value assignment
You can’t perform that action at this time.
0 commit comments