Ask Your Question
2

What is the way to retrieve soft-deleted entity in typeorm postgreSQL?

asked 2023-05-16 06:16:21 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-16 06:36:02 +0000

plato gravatar image

To retrieve soft-deleted entities in TypeORM PostgreSQl, you can use the find method with an additional withDeleted method. Here is an example:

const deletedEntities = await repository.find({ withDeleted: true });

This will fetch all the entities, including the ones that were soft-deleted. You can also filter the retrieved entities further by using the where option.

const deletedEntities = await repository.find({
    withDeleted: true,
    where: { deletedAt: Not(null) } 
});

This will retrieve all the entities that have a deletedAt field with a value, indicating that they have been soft-deleted.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-16 06:16:21 +0000

Seen: 15 times

Last updated: May 16 '23