@@ -7,8 +7,8 @@ import { fieldAffectsData } from 'payload/types'
77import type { BlocksMap } from '../../utilities/createBlocksMap'
88
99import { transformHasManyNumber } from './hasManyNumber'
10- import { transformRelationship } from './relationship'
1110import { transformHasManyText } from './hasManyText'
11+ import { transformRelationship } from './relationship'
1212
1313type TraverseFieldsArgs = {
1414 /**
@@ -35,10 +35,6 @@ type TraverseFieldsArgs = {
3535 * An array of Payload fields to traverse
3636 */
3737 fields : ( Field | TabAsField ) [ ]
38- /**
39- * All hasMany text fields, as returned by Drizzle, keyed on an object by field path
40- */
41- texts : Record < string , Record < string , unknown > [ ] >
4238 /**
4339 * All hasMany number fields, as returned by Drizzle, keyed on an object by field path
4440 */
@@ -55,6 +51,10 @@ type TraverseFieldsArgs = {
5551 * Data structure representing the nearest table from db
5652 */
5753 table : Record < string , unknown >
54+ /**
55+ * All hasMany text fields, as returned by Drizzle, keyed on an object by field path
56+ */
57+ texts : Record < string , Record < string , unknown > [ ] >
5858}
5959
6060// Traverse fields recursively, transforming data
@@ -66,11 +66,11 @@ export const traverseFields = <T extends Record<string, unknown>>({
6666 deletions,
6767 fieldPrefix,
6868 fields,
69- texts,
7069 numbers,
7170 path,
7271 relationships,
7372 table,
73+ texts,
7474} : TraverseFieldsArgs ) : T => {
7575 const sanitizedPath = path ? `${ path } .` : path
7676
@@ -83,11 +83,11 @@ export const traverseFields = <T extends Record<string, unknown>>({
8383 deletions,
8484 fieldPrefix,
8585 fields : field . tabs . map ( ( tab ) => ( { ...tab , type : 'tab' } ) ) ,
86- texts,
8786 numbers,
8887 path,
8988 relationships,
9089 table,
90+ texts,
9191 } )
9292 }
9393
@@ -103,17 +103,22 @@ export const traverseFields = <T extends Record<string, unknown>>({
103103 deletions,
104104 fieldPrefix,
105105 fields : field . fields ,
106- texts,
107106 numbers,
108107 path,
109108 relationships,
110109 table,
110+ texts,
111111 } )
112112 }
113113
114114 if ( fieldAffectsData ( field ) ) {
115115 const fieldName = `${ fieldPrefix || '' } ${ field . name } `
116116 const fieldData = table [ fieldName ]
117+
118+ if ( fieldPrefix ) {
119+ deletions . push ( ( ) => delete table [ fieldName ] )
120+ }
121+
117122 if ( field . type === 'array' ) {
118123 if ( Array . isArray ( fieldData ) ) {
119124 if ( field . localized ) {
@@ -135,13 +140,17 @@ export const traverseFields = <T extends Record<string, unknown>>({
135140 deletions,
136141 fieldPrefix : '' ,
137142 fields : field . fields ,
138- texts,
139143 numbers,
140144 path : `${ sanitizedPath } ${ field . name } .${ row . _order - 1 } ` ,
141145 relationships,
142146 table : row ,
147+ texts,
143148 } )
144149
150+ if ( '_order' in rowResult ) {
151+ delete rowResult . _order
152+ }
153+
145154 arrayResult [ locale ] . push ( rowResult )
146155 }
147156
@@ -153,18 +162,23 @@ export const traverseFields = <T extends Record<string, unknown>>({
153162 row . id = row . _uuid
154163 delete row . _uuid
155164 }
165+
166+ if ( '_order' in row ) {
167+ delete row . _order
168+ }
169+
156170 return traverseFields < T > ( {
157171 blocks,
158172 config,
159173 dataRef : row ,
160174 deletions,
161175 fieldPrefix : '' ,
162176 fields : field . fields ,
163- texts,
164177 numbers,
165178 path : `${ sanitizedPath } ${ field . name } .${ i } ` ,
166179 relationships,
167180 table : row ,
181+ texts,
168182 } )
169183 } )
170184 }
@@ -204,11 +218,11 @@ export const traverseFields = <T extends Record<string, unknown>>({
204218 deletions,
205219 fieldPrefix : '' ,
206220 fields : block . fields ,
207- texts,
208221 numbers,
209222 path : `${ blockFieldPath } .${ row . _order - 1 } ` ,
210223 relationships,
211224 table : row ,
225+ texts,
212226 } )
213227
214228 delete blockResult . _order
@@ -235,11 +249,11 @@ export const traverseFields = <T extends Record<string, unknown>>({
235249 deletions,
236250 fieldPrefix : '' ,
237251 fields : block . fields ,
238- texts,
239252 numbers,
240253 path : `${ blockFieldPath } .${ i } ` ,
241254 relationships,
242255 table : row ,
256+ texts,
243257 } )
244258 }
245259
@@ -316,15 +330,15 @@ export const traverseFields = <T extends Record<string, unknown>>({
316330 transformHasManyText ( {
317331 field,
318332 locale,
319- textRows : texts ,
320333 ref : result ,
334+ textRows : texts ,
321335 } )
322336 } )
323337 } else {
324338 transformHasManyText ( {
325339 field,
326- textRows : textPathMatch ,
327340 ref : result ,
341+ textRows : textPathMatch ,
328342 } )
329343 }
330344
@@ -420,13 +434,16 @@ export const traverseFields = <T extends Record<string, unknown>>({
420434 deletions,
421435 fieldPrefix : groupFieldPrefix ,
422436 fields : field . fields ,
423- texts,
424437 numbers,
425438 path : `${ sanitizedPath } ${ field . name } ` ,
426439 relationships,
427440 table,
441+ texts,
428442 } )
429443 } )
444+ if ( '_order' in ref ) {
445+ delete ref . _order
446+ }
430447 } else {
431448 const groupData = { }
432449
@@ -437,12 +454,15 @@ export const traverseFields = <T extends Record<string, unknown>>({
437454 deletions,
438455 fieldPrefix : groupFieldPrefix ,
439456 fields : field . fields ,
440- texts,
441457 numbers,
442458 path : `${ sanitizedPath } ${ field . name } ` ,
443459 relationships,
444460 table,
461+ texts,
445462 } )
463+ if ( '_order' in ref ) {
464+ delete ref . _order
465+ }
446466 }
447467
448468 break
0 commit comments