Open rahul-rocket opened 4 months ago
@Char2sGu Okay. So below code is working to recover it, but still not sure how to recover deleted relationships.
// Reset the soft-delete flag to "recover" the entity
wrap(entity as BaseEntity).assign({ deletedAt: null });
// Persist all changes to ensure recovery is complete
await this.mikroOrmRepository.persistAndFlush(entity);
Hey @rahul-rocket sorry for the delay. I am a little busy at the moment, but this has been added to my todo. Will look into it in a few days
On second thought, I should stop piling up my to-do list 😝
Currently, when an entity is soft-deleted, only this specific entity's deletedAt
property will be updated. The relations will not be updated (but the relations will not appear in queries because of the filter). Therefore, if I didn't confuse myself, simply query the deleted entity with the filters disabled, and set deletedAt
back to its initial value should recover the entity.
I'm not pretty sure if this should be added as a new method since this process seems pretty straightforward. Do you have some suggestions on the API you expect to see? @rahul-rocket
@Char2sGu We are building amazing platform where we used 2 ORMs (TypeORM & MikroORM) together. So TypeORM provide additional method to recover it.
i.e. recover<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;
So TypeORM can also soft deleted relations too if we passed them with Entity. But not sure how Mikro ORM (this package) doing it.
Note: Anyway i have fixed this issue by some other hacked. But check below link and let me know if you have any suggestion for me.
https://github.com/ever-co/ever-gauzy/blob/develop/packages/core/src/core/crud/crud.service.ts#L684
On second thought, I should stop piling up my to-do list 😝
Currently, when an entity is soft-deleted, only this specific entity's
deletedAt
property will be updated. The relations will not be updated (but the relations will not appear in queries because of the filter). Therefore, if I didn't confuse myself, simply query the deleted entity with the filters disabled, and setdeletedAt
back to its initial value should recover the entity.I'm not pretty sure if this should be added as a new method since this process seems pretty straightforward. Do you have some suggestions on the API you expect to see? @rahul-rocket
My suggestion is that we should add some additional method Recover
to entity same as TypeORM if it is possible.
On second thought, I should stop piling up my to-do list 😝
Currently, when an entity is soft-deleted, only this specific entity's
deletedAt
property will be updated. The relations will not be updated (but the relations will not appear in queries because of the filter). Therefore, if I didn't confuse myself, simply query the deleted entity with the filters disabled, and setdeletedAt
back to its initial value should recover the entity.I'm not pretty sure if this should be added as a new method since this process seems pretty straightforward. Do you have some suggestions on the API you expect to see? @rahul-rocket
this is not true to be honest. at least for me it deletes the loaded @OneToMany relationships for example. is this expected?
this is not true to be honest. at least for me it deletes the loaded @OneToMany relationships for example. is this expected?
This is not expected. MikroORM might have changed its internal strategies.
Ur always welcome to create PRs for tests and updates.
Description: It would be helpful to have an option to recover entities that have been soft-deleted. This feature would enable users to restore entities to their original state, rather than permanently losing them due to soft deletion.
Feature Request:
Benefits: