@@ -939,17 +939,8 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
939939 combinedWhere = Object . keys ( combinedWhere ) . length > 0 ? { AND : [ parentWhere , combinedWhere ] } : parentWhere ;
940940 }
941941
942- // fill in automatically updated fields
943942 const modelDef = this . requireModel ( model ) ;
944943 let finalData = data ;
945- for ( const [ fieldName , fieldDef ] of Object . entries ( modelDef . fields ) ) {
946- if ( fieldDef . updatedAt ) {
947- if ( finalData === data ) {
948- finalData = clone ( data ) ;
949- }
950- finalData [ fieldName ] = this . dialect . transformPrimitive ( new Date ( ) , 'DateTime' , false ) ;
951- }
952- }
953944
954945 if ( Object . keys ( finalData ) . length === 0 ) {
955946 // nothing to update, return the original filter so that caller can identify the entity
@@ -1027,6 +1018,19 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
10271018 }
10281019 }
10291020
1021+ // fill in automatically updated fields
1022+ const scalarFields = Object . values ( modelDef . fields )
1023+ . filter ( ( f ) => ! f . relation )
1024+ . map ( ( f ) => f . name ) ;
1025+ if ( Object . keys ( updateFields ) . some ( ( f ) => scalarFields . includes ( f ) ) ) {
1026+ // if any scalar fields are being updated, also update the `updatedAt` fields
1027+ for ( const [ fieldName , fieldDef ] of Object . entries ( modelDef . fields ) ) {
1028+ if ( fieldDef . updatedAt ) {
1029+ updateFields [ fieldName ] = this . dialect . transformPrimitive ( new Date ( ) , 'DateTime' , false ) ;
1030+ }
1031+ }
1032+ }
1033+
10301034 if ( Object . keys ( updateFields ) . length === 0 ) {
10311035 // nothing to update, return the filter so that the caller can identify the entity
10321036 return combinedWhere ;
@@ -2073,22 +2077,11 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
20732077 }
20742078 }
20752079
2076- // Given a unique filter of a model, return the entity ids by trying to
2077- // reused the filter if it's a complete id filter (without extra fields)
2078- // otherwise, read the entity by the filter
2080+ // Given a unique filter of a model, load the entity and return its id fields
20792081 private getEntityIds ( kysely : ToKysely < Schema > , model : GetModels < Schema > , uniqueFilter : any ) {
2080- const idFields : string [ ] = requireIdFields ( this . schema , model ) ;
2081- if (
2082- // all id fields are provided
2083- idFields . every ( ( f ) => f in uniqueFilter && uniqueFilter [ f ] !== undefined ) &&
2084- // no non-id filter exists
2085- Object . keys ( uniqueFilter ) . every ( ( k ) => idFields . includes ( k ) )
2086- ) {
2087- return uniqueFilter ;
2088- }
2089-
20902082 return this . readUnique ( kysely , model , {
20912083 where : uniqueFilter ,
2084+ select : this . makeIdSelect ( model ) ,
20922085 } ) ;
20932086 }
20942087
0 commit comments