-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Initial implementation of soft-deletes for Issue #534 #1165
Conversation
Needs way more testing before I would have any confidence of this being used.
For Issue #534 |
Questions:
|
* This column will store an soft delete date of the deleted object. | ||
* This date is set when you delete the object, and set to null when you restore it | ||
*/ | ||
export function SoftDeleteDateColumn(options?: ColumnOptions): Function { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a better alternative names for this decorator? This looks correct but a bit long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a simple DeletedAt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we then also change the CreateDate
and UpdateDate
decorators as well? I tried to conform to the existing decorators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah you are right, its not consistent. For some reason I thought they are called CreatedAt
and UpdatedAt
haha. No, we can't rename them since we also need a Column
postfix as used in all column decorators. @NoNameProvided any other suggestions for a more consistent decorator name?
Hi and thank you for your contribution. Can you please make a PR against
don't think we need such method.
I think yes.
but we need call it better
we do need. All find operations just delegate everything to query builder
test every scenario you imagine :) |
What I mean by that question is should we automatically exclude soft-deleted entities when a "user" (developer) is manually creating a query with the Right now, I am only adding in the soft-delete checks on the convenience methods like
Could you clarify? What do you mean change my approach? I tried to touch as few places as possible, while maintaining the same style of the existing code. |
Any ideas on the same we could use? Maybe |
Refactoring this now for the next branch |
i mean there are lot of changes in next branch and you'll need to refactor your code a bit
TBH Im not yet sure if this should be a querybuilder behaviour as well. If we include this in query builder it will look like a magic - user tries to build a custom query and query builder magically adds some conditions... Thats why for example |
also requesting @AlexMesser @daniel-lang thoughts |
@pleerock The more I think about it, the more I think that it should not magically inject anything into query builder. If this is noted in the doc's, then I think from a project perspective we have nothing to worry about. To me, if typeorm does not automatically add your joins, then it should not automatically add in the soft-delete restrictions. To deal with this, maybe with could add a "magic" method to query builder which adds the soft-delete restriction.
Then, I could also use that method in the backend of typeorm for all the EntityManager functions. The question that then comes up, is what about deleted related entities. Let's say I have a "Post" and "PostTag" which is soft-deletable. What happens when I use queryBuilder to select a Post and join PostTag. Would the Thoughts? |
I would argue this. not creating joins is because of performance reasons, while not loading deleted entities is the main reason for using soft delete and I would like to see it in the query builder as well. Ofc we should have a |
I am going to create a PR against next, should I close this PR? |
Closing this, new PR based on next |
@mrkmg I also strive more to this solution. Also we'll need to add method called "loadEagerRelations" or something like that for eager relations.
the main problem is that add extra query which may be unexpected for users since they are kinda build their own query from scratch using query builder. Really hard to decide. |
Doesn't it append to the current query only if the decorator is present? |
yes, of course |
Then I don't understand why it's a hard decision to make it the default? It won't affect anyone until they start to use the soft delete. |
Please continue conversation on the new PR #1192 |
Needs way more testing before I would have any confidence of this being used.
TODO