@@ -5,12 +5,15 @@ import type {
5
5
SanitizedGlobalConfig ,
6
6
} from 'payload'
7
7
8
+ import { fieldAffectsData } from 'payload/shared'
9
+
8
10
import { getRouteWithoutAdmin , isAdminRoute } from './shared.js'
9
11
10
12
type Args = {
11
13
adminRoute : string
12
14
config : SanitizedConfig
13
15
defaultIDType : Payload [ 'db' ] [ 'defaultIDType' ]
16
+ payload ?: Payload
14
17
route : string
15
18
}
16
19
@@ -22,23 +25,23 @@ type RouteInfo = {
22
25
globalSlug ?: string
23
26
}
24
27
25
- export function getRouteInfo ( { adminRoute, config, defaultIDType, route } : Args ) : RouteInfo {
28
+ export function getRouteInfo ( {
29
+ adminRoute,
30
+ config,
31
+ defaultIDType,
32
+ payload,
33
+ route,
34
+ } : Args ) : RouteInfo {
26
35
if ( isAdminRoute ( { adminRoute, config, route } ) ) {
27
36
const routeWithoutAdmin = getRouteWithoutAdmin ( { adminRoute, route } )
28
37
const routeSegments = routeWithoutAdmin . split ( '/' ) . filter ( Boolean )
29
38
const [ entityType , entitySlug , createOrID ] = routeSegments
30
39
const collectionSlug = entityType === 'collections' ? entitySlug : undefined
31
40
const globalSlug = entityType === 'globals' ? entitySlug : undefined
32
41
33
- const docID =
34
- collectionSlug && createOrID !== 'create'
35
- ? defaultIDType === 'number'
36
- ? Number ( createOrID )
37
- : createOrID
38
- : undefined
39
-
40
42
let collectionConfig : SanitizedCollectionConfig | undefined
41
43
let globalConfig : SanitizedGlobalConfig | undefined
44
+ let idType = defaultIDType
42
45
43
46
if ( collectionSlug ) {
44
47
collectionConfig = config . collections . find ( ( collection ) => collection . slug === collectionSlug )
@@ -48,6 +51,20 @@ export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args)
48
51
globalConfig = config . globals . find ( ( global ) => global . slug === globalSlug )
49
52
}
50
53
54
+ // If the collection has an ID field, we need to determine the type of the ID field
55
+ if ( collectionConfig && payload ) {
56
+ if ( payload . collections ?. [ collectionSlug ] ) {
57
+ idType = payload . collections ?. [ collectionSlug ] . customIDType
58
+ }
59
+ }
60
+
61
+ const docID =
62
+ collectionSlug && createOrID !== 'create'
63
+ ? idType === 'number'
64
+ ? Number ( createOrID )
65
+ : createOrID
66
+ : undefined
67
+
51
68
return {
52
69
collectionConfig,
53
70
collectionSlug,
0 commit comments