@@ -38,6 +38,7 @@ const processRelationshipValues = (
3838 config : SanitizedConfig ,
3939 operation : 'read' | 'write' ,
4040 validateRelationships : boolean ,
41+ adapter : MongooseAdapter ,
4142) => {
4243 return items . map ( ( item ) => {
4344 // Handle polymorphic relationships
@@ -47,6 +48,7 @@ const processRelationshipValues = (
4748 return {
4849 relationTo : item . relationTo ,
4950 value : convertRelationshipValue ( {
51+ adapter,
5052 operation,
5153 relatedCollection,
5254 validateRelationships,
@@ -62,6 +64,7 @@ const processRelationshipValues = (
6264 const relatedCollection = config . collections ?. find ( ( { slug } ) => slug === field . relationTo )
6365 if ( relatedCollection ) {
6466 return convertRelationshipValue ( {
67+ adapter,
6568 operation,
6669 relatedCollection,
6770 validateRelationships,
@@ -75,11 +78,13 @@ const processRelationshipValues = (
7578}
7679
7780const convertRelationshipValue = ( {
81+ adapter,
7882 operation,
7983 relatedCollection,
8084 validateRelationships,
8185 value,
8286} : {
87+ adapter : MongooseAdapter
8388 operation : Args [ 'operation' ]
8489 relatedCollection : CollectionConfig
8590 validateRelationships ?: boolean
@@ -94,6 +99,14 @@ const convertRelationshipValue = ({
9499 return value . toHexString ( )
95100 }
96101
102+ if (
103+ customIDField ?. type === 'number' &&
104+ typeof value === 'bigint' &&
105+ adapter . useBigIntForNumberIDs
106+ ) {
107+ return Number ( value )
108+ }
109+
97110 return value
98111 }
99112
@@ -116,6 +129,7 @@ const convertRelationshipValue = ({
116129}
117130
118131const sanitizeRelationship = ( {
132+ adapter,
119133 config,
120134 field,
121135 locale,
@@ -124,6 +138,7 @@ const sanitizeRelationship = ({
124138 validateRelationships,
125139 value,
126140} : {
141+ adapter : MongooseAdapter
127142 config : SanitizedConfig
128143 field : JoinField | RelationshipField | UploadField
129144 locale ?: string
@@ -175,6 +190,7 @@ const sanitizeRelationship = ({
175190 return {
176191 relationTo : val . relationTo ,
177192 value : convertRelationshipValue ( {
193+ adapter,
178194 operation,
179195 relatedCollection : relatedCollectionForSingleValue ,
180196 validateRelationships,
@@ -186,6 +202,7 @@ const sanitizeRelationship = ({
186202
187203 if ( relatedCollection ) {
188204 return convertRelationshipValue ( {
205+ adapter,
189206 operation,
190207 relatedCollection,
191208 validateRelationships,
@@ -204,6 +221,7 @@ const sanitizeRelationship = ({
204221 result = {
205222 relationTo : value . relationTo ,
206223 value : convertRelationshipValue ( {
224+ adapter,
207225 operation,
208226 relatedCollection,
209227 validateRelationships,
@@ -215,6 +233,7 @@ const sanitizeRelationship = ({
215233 // Handle has one
216234 else if ( relatedCollection ) {
217235 result = convertRelationshipValue ( {
236+ adapter,
218237 operation,
219238 relatedCollection,
220239 validateRelationships,
@@ -657,6 +676,7 @@ export const transform = ({
657676 config ,
658677 operation ,
659678 validateRelationships ,
679+ adapter ,
660680 )
661681 $addToSet [ `${ parentPath } ${ field . name } .${ localeKey } ` ] = { $each : processedLocaleItems }
662682 }
@@ -675,6 +695,7 @@ export const transform = ({
675695 config ,
676696 operation ,
677697 validateRelationships ,
698+ adapter ,
678699 )
679700 $addToSet [ `${ parentPath } ${ field . name } ` ] = { $each : processedItems }
680701 delete ref [ field . name ]
@@ -721,6 +742,7 @@ export const transform = ({
721742 config ,
722743 operation ,
723744 validateRelationships ,
745+ adapter ,
724746 )
725747 $pull [ `${ parentPath } ${ field . name } .${ localeKey } ` ] = { $in : processedLocaleItems }
726748 }
@@ -739,6 +761,7 @@ export const transform = ({
739761 config ,
740762 operation ,
741763 validateRelationships ,
764+ adapter ,
742765 )
743766 $pull [ `${ parentPath } ${ field . name } ` ] = { $in : processedItems }
744767 delete ref [ field . name ]
@@ -792,6 +815,7 @@ export const transform = ({
792815 const value = fieldRef [ code ]
793816 if ( value ) {
794817 sanitizeRelationship ( {
818+ adapter,
795819 config,
796820 field,
797821 locale : code ,
@@ -805,6 +829,7 @@ export const transform = ({
805829 } else {
806830 // handle non-localized relationships
807831 sanitizeRelationship ( {
832+ adapter,
808833 config,
809834 field,
810835 locale : undefined ,
0 commit comments