How can I get soft deleted entity from typeorm postgreSQL?
I found out there is another solution. You can use the querybuilders .withDeleted()
method to also return soft deleted entities.
Example
const query = await this.manager .getRepository(FolderEntity) .createQueryBuilder('folder') .leftJoinAndSelect('folder.subStatus', 'status') .withDeleted() .getMany()
Actually referring to the findOptions doc you can pass the withDeleted
boolean that will retrieve the soft deleted rows.
for example:
const result = await this.repo.find({ where: { id }, withDeleted: true })
After more searching I found that only solution is to use raw sql query for that as it is shown in typeorm docs at the query block.
const deletedEntity = await connection .getRepository(Entity) .query(`SELECT * FROM Entity where id = '${deletedEntityId}'`)
This query returns values with deletedAt timestamp.