Skip to content

Commit a3bcda0

Browse files
hitesh-sourcefusedhmlau
authored andcommitted
fix(sequelize): "'Entity Not Found' error on updateById with MySQL"
"MySQL 'updateById' triggers 'entity not found' due to 0 affected rows." Signed-off-by: Hitesh Baliyan <[email protected]>
1 parent cd60919 commit a3bcda0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ benchmark/dist
3939
# Docs preview
4040
docs/_loopback.io/
4141
docs/_preview/
42+
43+
#Vscode local history
44+
.history

extensions/sequelize/src/sequelize/sequelize.repository.base.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ export class SequelizeCrudRepository<
227227
(where as AnyObject)[idProp] = id;
228228
const result = await this.updateAll(data, where, options);
229229
if (result.count === 0) {
230-
throw new EntityNotFoundError(this.entityClass, id);
230+
// as MySQL didn't provide affected rows when the values are same as what database have
231+
if (this.dataSource.config.connector === 'mysql') {
232+
const entity = await this.findById(id);
233+
if (!entity) throw new EntityNotFoundError(this.entityClass, id);
234+
} else {
235+
throw new EntityNotFoundError(this.entityClass, id);
236+
}
231237
}
232238
}
233239

0 commit comments

Comments
 (0)