@@ -939,15 +939,18 @@ 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 ;
944+
945+ // fill in automatically updated fields
946+ const autoUpdatedFields : string [ ] = [ ] ;
945947 for ( const [ fieldName , fieldDef ] of Object . entries ( modelDef . fields ) ) {
946948 if ( fieldDef . updatedAt ) {
947949 if ( finalData === data ) {
948950 finalData = clone ( data ) ;
949951 }
950952 finalData [ fieldName ] = this . dialect . transformPrimitive ( new Date ( ) , 'DateTime' , false ) ;
953+ autoUpdatedFields . push ( fieldName ) ;
951954 }
952955 }
953956
@@ -1027,7 +1030,13 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
10271030 }
10281031 }
10291032
1030- if ( Object . keys ( updateFields ) . length === 0 ) {
1033+ let hasFieldUpdate = Object . keys ( updateFields ) . length > 0 ;
1034+ if ( hasFieldUpdate ) {
1035+ // check if only updating auto-updated fields, if so, we can skip the update
1036+ hasFieldUpdate = Object . keys ( updateFields ) . some ( ( f ) => ! autoUpdatedFields . includes ( f ) ) ;
1037+ }
1038+
1039+ if ( ! hasFieldUpdate ) {
10311040 // nothing to update, return the filter so that the caller can identify the entity
10321041 return combinedWhere ;
10331042 } else {
@@ -2073,22 +2082,11 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
20732082 }
20742083 }
20752084
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
2085+ // Given a unique filter of a model, load the entity and return its id fields
20792086 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-
20902087 return this . readUnique ( kysely , model , {
20912088 where : uniqueFilter ,
2089+ select : this . makeIdSelect ( model ) ,
20922090 } ) ;
20932091 }
20942092
0 commit comments