@@ -77,6 +77,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
77
77
this . injectWhereHierarchy ( model , args ?. where ) ;
78
78
this . injectSelectIncludeHierarchy ( model , args ) ;
79
79
80
+ if ( args . orderBy ) {
81
+ // `orderBy` may contain fields from base types
82
+ args . orderBy = this . buildWhereHierarchy ( this . model , args . orderBy ) ;
83
+ }
84
+
80
85
if ( this . options . logPrismaQuery ) {
81
86
this . logger . info ( `[delegate] \`${ method } \` ${ this . getModelName ( model ) } : ${ formatObject ( args ) } ` ) ;
82
87
}
@@ -126,19 +131,19 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
126
131
} ) ;
127
132
}
128
133
129
- private buildWhereHierarchy ( where : any ) {
134
+ private buildWhereHierarchy ( model : string , where : any ) {
130
135
if ( ! where ) {
131
136
return undefined ;
132
137
}
133
138
134
139
where = deepcopy ( where ) ;
135
140
Object . entries ( where ) . forEach ( ( [ field , value ] ) => {
136
- const fieldInfo = resolveField ( this . options . modelMeta , this . model , field ) ;
141
+ const fieldInfo = resolveField ( this . options . modelMeta , model , field ) ;
137
142
if ( ! fieldInfo ?. inheritedFrom ) {
138
143
return ;
139
144
}
140
145
141
- let base = this . getBaseModel ( this . model ) ;
146
+ let base = this . getBaseModel ( model ) ;
142
147
let target = where ;
143
148
144
149
while ( base ) {
@@ -173,12 +178,17 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
173
178
174
179
for ( const kind of [ 'select' , 'include' ] as const ) {
175
180
if ( args [ kind ] && typeof args [ kind ] === 'object' ) {
176
- for ( const [ field , value ] of Object . entries ( args [ kind ] ) ) {
177
- if ( value !== undefined ) {
181
+ for ( const [ field , value ] of Object . entries < any > ( args [ kind ] ) ) {
182
+ const fieldInfo = resolveField ( this . options . modelMeta , model , field ) ;
183
+ if ( fieldInfo && value !== undefined ) {
184
+ if ( value ?. orderBy ) {
185
+ // `orderBy` may contain fields from base types
186
+ value . orderBy = this . buildWhereHierarchy ( fieldInfo . type , value . orderBy ) ;
187
+ }
188
+
178
189
if ( this . injectBaseFieldSelect ( model , field , value , args , kind ) ) {
179
190
delete args [ kind ] [ field ] ;
180
191
} else {
181
- const fieldInfo = resolveField ( this . options . modelMeta , model , field ) ;
182
192
if ( fieldInfo && this . isDelegateOrDescendantOfDelegate ( fieldInfo . type ) ) {
183
193
let nextValue = value ;
184
194
if ( nextValue === true ) {
@@ -847,15 +857,15 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
847
857
args = deepcopy ( args ) ;
848
858
849
859
if ( args . cursor ) {
850
- args . cursor = this . buildWhereHierarchy ( args . cursor ) ;
860
+ args . cursor = this . buildWhereHierarchy ( this . model , args . cursor ) ;
851
861
}
852
862
853
863
if ( args . orderBy ) {
854
- args . orderBy = this . buildWhereHierarchy ( args . orderBy ) ;
864
+ args . orderBy = this . buildWhereHierarchy ( this . model , args . orderBy ) ;
855
865
}
856
866
857
867
if ( args . where ) {
858
- args . where = this . buildWhereHierarchy ( args . where ) ;
868
+ args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
859
869
}
860
870
861
871
if ( this . options . logPrismaQuery ) {
@@ -875,11 +885,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
875
885
args = deepcopy ( args ) ;
876
886
877
887
if ( args ?. cursor ) {
878
- args . cursor = this . buildWhereHierarchy ( args . cursor ) ;
888
+ args . cursor = this . buildWhereHierarchy ( this . model , args . cursor ) ;
879
889
}
880
890
881
891
if ( args ?. where ) {
882
- args . where = this . buildWhereHierarchy ( args . where ) ;
892
+ args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
883
893
}
884
894
885
895
if ( this . options . logPrismaQuery ) {
@@ -915,7 +925,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
915
925
args = deepcopy ( args ) ;
916
926
917
927
if ( args . where ) {
918
- args . where = this . buildWhereHierarchy ( args . where ) ;
928
+ args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
919
929
}
920
930
921
931
if ( this . options . logPrismaQuery ) {
0 commit comments