diff --git a/packages/repository/src/repositories/legacy-juggler-bridge.ts b/packages/repository/src/repositories/legacy-juggler-bridge.ts index 8b5732239aaa..4d2bb6ea63e3 100644 --- a/packages/repository/src/repositories/legacy-juggler-bridge.ts +++ b/packages/repository/src/repositories/legacy-juggler-bridge.ts @@ -128,7 +128,7 @@ export class DefaultCrudRepository this.modelClass = dataSource.createModel( definition.name, properties, - Object.assign({strict: true}, definition.settings), + Object.assign({strict: true}, {strictDelete: true}, definition.settings), ); this.modelClass.attachTo(dataSource); } diff --git a/packages/repository/test/unit/repositories/crud.repository.unit.ts b/packages/repository/test/unit/repositories/crud.repository.unit.ts index 7f34cb813ff2..9510f1cac3f9 100644 --- a/packages/repository/test/unit/repositories/crud.repository.unit.ts +++ b/packages/repository/test/unit/repositories/crud.repository.unit.ts @@ -145,8 +145,10 @@ describe('CrudRepositoryImpl', () => { it('delete all entities', async () => { await repo.create({id: 1, email: 'john@example.com'}); await repo.create({id: 2, email: 'mary@example.com'}); - const count = await repo.deleteAll(); - expect(count).to.be.eql(2); + const deleteCount = await repo.deleteAll(); + expect(deleteCount).to.be.eql(2); + const count = await repo.count(); + expect(count).to.be.eql(0); }); it('count all entities', async () => { diff --git a/packages/repository/test/unit/repositories/legacy-juggler-bridge.unit.ts b/packages/repository/test/unit/repositories/legacy-juggler-bridge.unit.ts index eeb1561c303f..cc7823371427 100644 --- a/packages/repository/test/unit/repositories/legacy-juggler-bridge.unit.ts +++ b/packages/repository/test/unit/repositories/legacy-juggler-bridge.unit.ts @@ -187,8 +187,10 @@ describe('DefaultCrudRepository', () => { it('implements Repository.delete()', async () => { const repo = new DefaultCrudRepository(Note, ds); const note = await repo.create({title: 't3', content: 'c3'}); - const result = await repo.delete(note); - expect(result).to.eql(true); + const deleteResult = await repo.delete(note); + expect(deleteResult).to.eql(true); + const findResult = await repo.find({where: {title: 't3'}}); + expect(findResult.length).to.eql(0); }); it('implements Repository.deleteById()', async () => { @@ -196,14 +198,29 @@ describe('DefaultCrudRepository', () => { const note = await repo.create({title: 't3', content: 'c3'}); const result = await repo.deleteById(note.id); expect(result).to.eql(true); + await expect(repo.findById(note.id)).to.be.rejectedWith( + `no ${repo.modelClass.name} found with id "${note.id}"`, + ); }); it('implements Repository.deleteAll()', async () => { const repo = new DefaultCrudRepository(Note, ds); await repo.create({title: 't3', content: 'c3'}); await repo.create({title: 't4', content: 'c4'}); - const result = await repo.deleteAll({title: 't3'}); - expect(result).to.eql(1); + const deleteCount = await repo.deleteAll(); + expect(deleteCount).to.eql(2); + const count = await repo.count(); + expect(count).to.eql(0); + }); + + it('implements Repository.deleteAll()', async () => { + const repo = new DefaultCrudRepository(Note, ds); + await repo.create({title: 't3', content: 'c3'}); + await repo.create({title: 't4', content: 'c4'}); + const deleteCount = await repo.deleteAll({title: 't3'}); + expect(deleteCount).to.eql(1); + const result = await repo.findOne({where: {title: 't3'}}); + expect(result).to.eql(null); }); it('implements Repository.updateById()', async () => {