Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const countGlobalVersionsOperation = async <TSlug extends GlobalSlug>(

const result = await payload.db.countGlobalVersions({
global: global.slug,
locale: req?.locale || undefined,
req,
where: fullWhere,
})
Expand Down
31 changes: 31 additions & 0 deletions test/localization/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4558,6 +4558,37 @@ describe('Localization', () => {
})
expect(result2.totalDocs).toBe(1)
})

it('should count global versions with query on localized field respecting locale', async () => {
await payload.updateGlobal({
slug: globalWithDraftsSlug,
data: { text: 'global count en', _status: 'published' },
locale: defaultLocale,
})

await payload.updateGlobal({
slug: globalWithDraftsSlug,
data: { text: 'global count es', _status: 'published' },
locale: spanishLocale,
})

const englishWhere = { 'version.text': { equals: 'global count en' } }

const inEnglish = await payload.countGlobalVersions({
global: globalWithDraftsSlug,
locale: defaultLocale,
where: englishWhere,
})

const inSpanish = await payload.countGlobalVersions({
global: globalWithDraftsSlug,
locale: spanishLocale,
where: englishWhere,
})

expect(inEnglish.totalDocs).toBeGreaterThan(0)
expect(inSpanish.totalDocs).toBe(0)
})
})
})

Expand Down
Loading