@@ -100,9 +100,14 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
100
100
if ( ! filters . operator ) {
101
101
return { ok : false , error : `Field "operator" not specified in filter object: ${ JSON . stringify ( filters ) } ` } ;
102
102
}
103
- if ( filtersAsSingle . value === undefined ) {
103
+ // Either compare with value or with rightField (field-to-field). If rightField is set, value must be undefined.
104
+ const comparingWithRightField = filtersAsSingle . rightField !== undefined && filtersAsSingle . rightField !== null ;
105
+ if ( ! comparingWithRightField && filtersAsSingle . value === undefined ) {
104
106
return { ok : false , error : `Field "value" not specified in filter object: ${ JSON . stringify ( filters ) } ` } ;
105
107
}
108
+ if ( comparingWithRightField && filtersAsSingle . value !== undefined ) {
109
+ return { ok : false , error : `Specify either "value" or "rightField", not both: ${ JSON . stringify ( filters ) } ` } ;
110
+ }
106
111
if ( filtersAsSingle . insecureRawSQL ) {
107
112
return { ok : false , error : `Field "insecureRawSQL" should not be specified in filter object alongside "field": ${ JSON . stringify ( filters ) } ` } ;
108
113
}
@@ -137,7 +142,15 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
137
142
}
138
143
}
139
144
// value normalization
140
- if ( filters . operator == AdminForthFilterOperators . IN || filters . operator == AdminForthFilterOperators . NIN ) {
145
+ if ( comparingWithRightField ) {
146
+ // ensure rightField exists in resource
147
+ const rightFieldObj = resource . dataSourceColumns . find ( ( col ) => col . name == filtersAsSingle . rightField ) ;
148
+ if ( ! rightFieldObj ) {
149
+ const similar = suggestIfTypo ( resource . dataSourceColumns . map ( ( col ) => col . name ) , filtersAsSingle . rightField as string ) ;
150
+ throw new Error ( `Field '${ filtersAsSingle . rightField } ' not found in resource '${ resource . resourceId } '. ${ similar ? `Did you mean '${ similar } '?` : '' } ` ) ;
151
+ }
152
+ // No value conversion needed for field-to-field comparison here
153
+ } else if ( filters . operator == AdminForthFilterOperators . IN || filters . operator == AdminForthFilterOperators . NIN ) {
141
154
if ( ! Array . isArray ( filters . value ) ) {
142
155
return { ok : false , error : `Value for operator '${ filters . operator } ' should be an array, in filter object: ${ JSON . stringify ( filters ) } ` } ;
143
156
}
0 commit comments