Skip to content

Commit e1168a0

Browse files
fix: count versions should allow querying on localized fields (#14695)
`payload.countVersions` was not passing the locale through, so it was not possible to query on localized fields without querying on the localized path. This differed from how the find operation works.
1 parent ba5834b commit e1168a0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/payload/src/collections/operations/countVersions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const countVersionsOperation = async <TSlug extends CollectionSlug>(
5050
where,
5151
} = args
5252

53-
const { payload } = req!
53+
const { locale, payload } = req!
5454

5555
// /////////////////////////////////////
5656
// Access
@@ -90,6 +90,7 @@ export const countVersionsOperation = async <TSlug extends CollectionSlug>(
9090

9191
result = await payload.db.countVersions({
9292
collection: collectionConfig.slug,
93+
locale: locale!,
9394
req,
9495
where: fullWhere,
9596
})

test/localization/int.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
englishTitle,
3333
hungarianLocale,
3434
localizedDateFieldsSlug,
35+
localizedDraftsSlug,
3536
localizedPostsSlug,
3637
localizedSortSlug,
3738
portugueseLocale,
@@ -3617,6 +3618,28 @@ describe('Localization', () => {
36173618
expect(queriedDoc.docs[0]!.id).toBe(doc.id)
36183619
})
36193620
})
3621+
3622+
describe('localized queries', () => {
3623+
it('should count versions with query on localized field', async () => {
3624+
await payload.create({
3625+
collection: localizedDraftsSlug,
3626+
data: {
3627+
title: 'Localized Drafts EN',
3628+
},
3629+
locale: defaultLocale,
3630+
})
3631+
3632+
const result2 = await payload.countVersions({
3633+
collection: localizedDraftsSlug,
3634+
where: {
3635+
'version.title': {
3636+
equals: 'Localized Drafts EN',
3637+
},
3638+
},
3639+
})
3640+
expect(result2.totalDocs).toBe(1)
3641+
})
3642+
})
36203643
})
36213644

36223645
async function createLocalizedPost(data: {

0 commit comments

Comments
 (0)