Skip to content

Commit cc99c3a

Browse files
chore: improves getLatestCollectionVersion where constraints (#8747)
1 parent 24a8dc7 commit cc99c3a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/payload/src/versions/drafts/appendVersionToQueryKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Where } from '../../types'
22

3-
export const appendVersionToQueryKey = (query: Where): Where => {
3+
export const appendVersionToQueryKey = (query: Where = {}): Where => {
44
return Object.entries(query).reduce((res, [key, val]) => {
55
if (['AND', 'OR', 'and', 'or'].includes(key) && Array.isArray(val)) {
66
return {

packages/payload/src/versions/getLatestCollectionVersion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import type { Payload } from '../payload'
44
import type { PayloadRequest } from '../types'
55
import type { TypeWithVersion } from './types'
66

7+
import { combineQueries } from '../database/combineQueries'
78
import { docHasTimestamps } from '../types'
9+
import { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey'
810

911
type Args = {
1012
config: SanitizedCollectionConfig
@@ -32,7 +34,7 @@ export const getLatestCollectionVersion = async <T extends TypeWithID = any>({
3234
pagination: false,
3335
req,
3436
sort: '-updatedAt',
35-
where: { parent: { equals: id } },
37+
where: combineQueries(appendVersionToQueryKey(query.where), { parent: { equals: id } }),
3638
})
3739
;[latestVersion] = docs
3840
}

0 commit comments

Comments
 (0)