@@ -7,13 +7,13 @@ import {
77 FieldInfo ,
88 ModelInfo ,
99 NestedWriteVisitor ,
10+ clone ,
1011 enumerate ,
1112 getIdFields ,
1213 getModelInfo ,
1314 isDelegateModel ,
1415 resolveField ,
1516} from '../cross' ;
16- import { clone } from '../cross' ;
1717import type { CrudContract , DbClientContract } from '../types' ;
1818import type { InternalEnhancementOptions } from './create-enhancement' ;
1919import { Logger } from './logger' ;
@@ -79,7 +79,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
7979
8080 if ( args . orderBy ) {
8181 // `orderBy` may contain fields from base types
82- args . orderBy = this . buildWhereHierarchy ( this . model , args . orderBy ) ;
82+ this . injectWhereHierarchy ( this . model , args . orderBy ) ;
8383 }
8484
8585 if ( this . options . logPrismaQuery ) {
@@ -95,7 +95,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
9595 }
9696
9797 private injectWhereHierarchy ( model : string , where : any ) {
98- if ( ! where || typeof where !== 'object' ) {
98+ if ( ! where || ! isPlainObject ( where ) ) {
9999 return ;
100100 }
101101
@@ -108,44 +108,9 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
108108
109109 const fieldInfo = resolveField ( this . options . modelMeta , model , field ) ;
110110 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 ) ;
135113 }
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 ) {
149114 return ;
150115 }
151116
@@ -164,6 +129,9 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
164129 }
165130
166131 if ( base . name === fieldInfo . inheritedFrom ) {
132+ if ( fieldInfo . isDataModel ) {
133+ this . injectWhereHierarchy ( base . name , value ) ;
134+ }
167135 thisLayer [ field ] = value ;
168136 delete where [ field ] ;
169137 break ;
@@ -173,8 +141,6 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
173141 }
174142 }
175143 } ) ;
176-
177- return where ;
178144 }
179145
180146 private injectSelectIncludeHierarchy ( model : string , args : any ) {
@@ -189,7 +155,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
189155 if ( fieldInfo && value !== undefined ) {
190156 if ( value ?. orderBy ) {
191157 // `orderBy` may contain fields from base types
192- value . orderBy = this . buildWhereHierarchy ( fieldInfo . type , value . orderBy ) ;
158+ this . injectWhereHierarchy ( fieldInfo . type , value . orderBy ) ;
193159 }
194160
195161 if ( this . injectBaseFieldSelect ( model , field , value , args , kind ) ) {
@@ -921,15 +887,15 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
921887 args = clone ( args ) ;
922888
923889 if ( args . cursor ) {
924- args . cursor = this . buildWhereHierarchy ( this . model , args . cursor ) ;
890+ this . injectWhereHierarchy ( this . model , args . cursor ) ;
925891 }
926892
927893 if ( args . orderBy ) {
928- args . orderBy = this . buildWhereHierarchy ( this . model , args . orderBy ) ;
894+ this . injectWhereHierarchy ( this . model , args . orderBy ) ;
929895 }
930896
931897 if ( args . where ) {
932- args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
898+ this . injectWhereHierarchy ( this . model , args . where ) ;
933899 }
934900
935901 if ( this . options . logPrismaQuery ) {
@@ -949,11 +915,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
949915 args = clone ( args ) ;
950916
951917 if ( args ?. cursor ) {
952- args . cursor = this . buildWhereHierarchy ( this . model , args . cursor ) ;
918+ this . injectWhereHierarchy ( this . model , args . cursor ) ;
953919 }
954920
955921 if ( args ?. where ) {
956- args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
922+ this . injectWhereHierarchy ( this . model , args . where ) ;
957923 }
958924
959925 if ( this . options . logPrismaQuery ) {
@@ -989,7 +955,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
989955 args = clone ( args ) ;
990956
991957 if ( args . where ) {
992- args . where = this . buildWhereHierarchy ( this . model , args . where ) ;
958+ this . injectWhereHierarchy ( this . model , args . where ) ;
993959 }
994960
995961 if ( this . options . logPrismaQuery ) {
0 commit comments