Deleted entities not tracked in history
When an entity is soft deleted, the history log does not show this.
(See point 5 on this comment for more info on soft delete event behaviour: https://github.com/typeorm/typeorm/issues/534#issuecomment-535416895)
OK updates:
-
Calling
.delete()or.softDelete()does not emit an action that history can subscribe to, hence the history log not showing this. Calling.remove()or.softRemove()does emit an action. -
Calling
.softRemove()actually emits an update action, not a delete action. (See comment linked above). Not sure how you want to handle this @anchan828 ? If someone were to perform:create entity -> soft delete it -> recover it- what should history log show?CREATED, UPDATED, UPDATED? orCREATED, DELETED, RECOVERED?
Hi @harveyappleton,
1
The history pacakge supports ActiveRecord patterns. .delete() and .softDelete() are for manager and repository patterns, right?
At the moment, I can't support this unless the Subscriber can also pass entities via delete and softDelete 😔.
2
I can't support this unless the Subscriber can also pass delete date object... https://github.com/typeorm/typeorm/issues/6327
- It seems to be working for me, and I am using repository pattern not ActiveRecord pattern, so that's good! I think the
.delete()and.softDelete()methods don't emit events, but the remove equivalents do.. here's an excerpt from the typescript definition files for the entity manager:
* Deletes entities by a given condition(s).
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
* Executes fast and efficient DELETE query.
* Does not check if entity exist in the database.
* Condition(s) cannot be empty.
*/
- Ah ok, for now then I guess it can only be
CREATED, UPDATED, UPDATEDuntil we can get thedeleted_atcolumn value into the subscriber?
Thanks for the info.
-
My understanding is that Delete only deletes by a given condition, so it may not hold the entity. What this means is that you may have to use
.findto get the entity to create the History from original entity. -
Maybe yes. You can create an UPDATED event, but I think the deleted_at will be saved as null.
Solving this problem seems to be very difficult. I can’t come up with any good ideas, So I may need to change my perspective. 🤔
Thanks for awesome lib guys.
Just wanted to mention that ability to emit events on softDelete looks quite valuable and desired from my perspective too)
Hi, Sorry, I already don't use and don't maintain the history package. So I removed the package. I can't state clearly, but if you search for a similar package, you might try to use that one. Thanks for using it.