@@ -7,13 +7,13 @@ import {
7
7
FieldInfo ,
8
8
ModelInfo ,
9
9
NestedWriteVisitor ,
10
+ clone ,
10
11
enumerate ,
11
12
getIdFields ,
12
13
getModelInfo ,
13
14
isDelegateModel ,
14
15
resolveField ,
15
16
} from '../cross' ;
16
- import { clone } from '../cross' ;
17
17
import type { CrudContract , DbClientContract } from '../types' ;
18
18
import type { InternalEnhancementOptions } from './create-enhancement' ;
19
19
import { Logger } from './logger' ;
@@ -79,7 +79,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
79
79
80
80
if ( args . orderBy ) {
81
81
// `orderBy` may contain fields from base types
82
- args . orderBy = this . buildWhereHierarchy ( this . model , args . orderBy ) ;
82
+ this . injectWhereHierarchy ( this . model , args . orderBy ) ;
83
83
}
84
84
85
85
if ( this . options . logPrismaQuery ) {
@@ -95,7 +95,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
95
95
}
96
96
97
97
private injectWhereHierarchy ( model : string , where : any ) {
98
- if ( ! where || typeof where !== 'object' ) {
98
+ if ( ! where || ! isPlainObject ( where ) ) {
99
99
return ;
100
100
}
101
101
@@ -108,44 +108,9 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
108
108
109
109
const fieldInfo = resolveField ( this . options . modelMeta , model , field ) ;
110
110
if ( ! fieldInfo ?. inheritedFrom ) {
111
- return ;
112
- }
113
-
114
- let base = this . getBaseModel ( model ) ;
115
- let target = where ;
116
-
117
- while ( base ) {
118
- const baseRelationName = this . makeAuxRelationName ( base ) ;
119
-
120
- // prepare base layer where
121
- let thisLayer : any ;
122
- if ( target [ baseRelationName ] ) {
123
- thisLayer = target [ baseRelationName ] ;
124
- } else {
125
- thisLayer = target [ baseRelationName ] = { } ;
126
- }
127
-
128
- if ( base . name === fieldInfo . inheritedFrom ) {
129
- thisLayer [ field ] = value ;
130
- delete where [ field ] ;
131
- break ;
132
- } else {
133
- target = thisLayer ;
134
- base = this . getBaseModel ( base . name ) ;
111
+ if ( fieldInfo ?. isDataModel ) {
112
+ this . injectWhereHierarchy ( fieldInfo . type , value ) ;
135
113
}
136
- }
137
- } ) ;
138
- }
139
-
140
- private buildWhereHierarchy ( model : string , where : any ) {
141
- if ( ! where ) {
142
- return undefined ;
143
- }
144
-
145
- where = clone ( where ) ;
146
- Object . entries ( where ) . forEach ( ( [ field , value ] ) => {
147
- const fieldInfo = resolveField ( this . options . modelMeta , model , field ) ;
148
- if ( ! fieldInfo ?. inheritedFrom ) {
149
114
return ;
150
115
}
151
116
@@ -164,6 +129,9 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
164
129
}
165
130
166
131
if ( base . name === fieldInfo . inheritedFrom ) {
132
+ if ( fieldInfo . isDataModel ) {
133
+ this . injectWhereHierarchy ( base . name , value ) ;
134
+ }
167
135
thisLayer [ field ] = value ;
168
136
delete where [ field ] ;
169
137
break ;
@@ -173,8 +141,6 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
173
141
}
174
142
}
175
143
} ) ;
176
-
177
- return where ;
178
144
}
179
145
180
146
private injectSelectIncludeHierarchy ( model : string , args : any ) {
@@ -189,7 +155,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
189
155
if ( fieldInfo && value !== undefined ) {
190
156
if ( value ?. orderBy ) {
191
157
// `orderBy` may contain fields from base types
192
- value . orderBy = this . buildWhereHierarchy ( fieldInfo . type , value . orderBy ) ;
158
+ this . injectWhereHierarchy ( fieldInfo . type , value . orderBy ) ;
193
159
}
194
160
195
161
if ( this . injectBaseFieldSelect ( model , field , value , args , kind ) ) {
@@ -921,15 +887,15 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
921
887
args = clone ( args ) ;
922
888
923
889
if ( args . cursor ) {
924
- args . cursor = this . buildWhereHierarchy ( this . model , args . cursor ) ;
890
+ this . injectWhereHierarchy ( this . model , args . cursor ) ;
925
891
}
926
892
927
893
if ( args . orderBy ) {
928
- args . orderBy = this . buildWhereHierarchy ( this . model , args . orderBy ) ;
894
+ this . injectWhereHierarchy ( this . model , args . orderBy ) ;
929
895
}
930
896
931
897
if ( args . where ) {
932
- args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
898
+ this . injectWhereHierarchy ( this . model , args . where ) ;
933
899
}
934
900
935
901
if ( this . options . logPrismaQuery ) {
@@ -949,11 +915,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
949
915
args = clone ( args ) ;
950
916
951
917
if ( args ?. cursor ) {
952
- args . cursor = this . buildWhereHierarchy ( this . model , args . cursor ) ;
918
+ this . injectWhereHierarchy ( this . model , args . cursor ) ;
953
919
}
954
920
955
921
if ( args ?. where ) {
956
- args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
922
+ this . injectWhereHierarchy ( this . model , args . where ) ;
957
923
}
958
924
959
925
if ( this . options . logPrismaQuery ) {
@@ -989,7 +955,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
989
955
args = clone ( args ) ;
990
956
991
957
if ( args . where ) {
992
- args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
958
+ this . injectWhereHierarchy ( this . model , args . where ) ;
993
959
}
994
960
995
961
if ( this . options . logPrismaQuery ) {
0 commit comments