@@ -53,6 +53,7 @@ type Args = {
53
53
* If creating a new table name for arrays and blocks, this suffix should be appended to the table name
54
54
*/
55
55
tableNameSuffix ?: string
56
+ useAlias ?: boolean
56
57
/**
57
58
* The raw value of the query before sanitization
58
59
*/
@@ -78,6 +79,7 @@ export const getTableColumnFromPath = ({
78
79
selectFields,
79
80
tableName,
80
81
tableNameSuffix = '' ,
82
+ useAlias,
81
83
value,
82
84
} : Args ) : TableColumn => {
83
85
const fieldPath = incomingSegments [ 0 ]
@@ -139,6 +141,7 @@ export const getTableColumnFromPath = ({
139
141
selectFields,
140
142
tableName : newTableName ,
141
143
tableNameSuffix,
144
+ useAlias,
142
145
value,
143
146
} )
144
147
}
@@ -159,6 +162,7 @@ export const getTableColumnFromPath = ({
159
162
selectFields,
160
163
tableName : newTableName ,
161
164
tableNameSuffix : `${ tableNameSuffix } ${ toSnakeCase ( field . name ) } _` ,
165
+ useAlias,
162
166
value,
163
167
} )
164
168
}
@@ -177,6 +181,7 @@ export const getTableColumnFromPath = ({
177
181
selectFields,
178
182
tableName : newTableName ,
179
183
tableNameSuffix,
184
+ useAlias,
180
185
value,
181
186
} )
182
187
}
@@ -212,6 +217,7 @@ export const getTableColumnFromPath = ({
212
217
selectFields,
213
218
tableName : newTableName ,
214
219
tableNameSuffix : `${ tableNameSuffix } ${ toSnakeCase ( field . name ) } _` ,
220
+ useAlias,
215
221
value,
216
222
} )
217
223
}
@@ -339,6 +345,7 @@ export const getTableColumnFromPath = ({
339
345
rootTableName,
340
346
selectFields,
341
347
tableName : newTableName ,
348
+ useAlias,
342
349
value,
343
350
} )
344
351
}
@@ -397,6 +404,7 @@ export const getTableColumnFromPath = ({
397
404
rootTableName,
398
405
selectFields : blockSelectFields ,
399
406
tableName : newTableName ,
407
+ useAlias,
400
408
value,
401
409
} )
402
410
} catch ( error ) {
@@ -633,6 +641,7 @@ export const getTableColumnFromPath = ({
633
641
rootTableName : newTableName ,
634
642
selectFields,
635
643
tableName : newTableName ,
644
+ useAlias,
636
645
value,
637
646
} )
638
647
} else if (
@@ -685,6 +694,7 @@ export const getTableColumnFromPath = ({
685
694
pathSegments : pathSegments . slice ( 1 ) ,
686
695
selectFields,
687
696
tableName : newTableName ,
697
+ useAlias,
688
698
value,
689
699
} )
690
700
}
@@ -698,29 +708,35 @@ export const getTableColumnFromPath = ({
698
708
}
699
709
700
710
if ( fieldAffectsData ( field ) ) {
711
+ let newTable = adapter . tables [ newTableName ]
712
+
701
713
if ( field . localized && adapter . payload . config . localization ) {
702
714
// If localized, we go to localized table and set aliasTable to undefined
703
715
// so it is not picked up below to be used as targetTable
704
716
const parentTable = aliasTable || adapter . tables [ tableName ]
705
717
newTableName = `${ tableName } ${ adapter . localesSuffix } `
706
718
719
+ newTable = useAlias
720
+ ? getTableAlias ( { adapter, tableName : newTableName } ) . newAliasTable
721
+ : adapter . tables [ newTableName ]
722
+
707
723
joins . push ( {
708
- condition : eq ( parentTable . id , adapter . tables [ newTableName ] . _parentID ) ,
709
- table : adapter . tables [ newTableName ] ,
724
+ condition : eq ( parentTable . id , newTable . _parentID ) ,
725
+ table : newTable ,
710
726
} )
711
727
712
728
aliasTable = undefined
713
729
714
730
if ( locale !== 'all' ) {
715
731
constraints . push ( {
716
732
columnName : '_locale' ,
717
- table : adapter . tables [ newTableName ] ,
733
+ table : newTable ,
718
734
value : locale ,
719
735
} )
720
736
}
721
737
}
722
738
723
- const targetTable = aliasTable || adapter . tables [ newTableName ]
739
+ const targetTable = aliasTable || newTable
724
740
725
741
selectFields [ `${ newTableName } .${ columnPrefix } ${ field . name } ` ] =
726
742
targetTable [ `${ columnPrefix } ${ field . name } ` ]
0 commit comments