-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: resolve issue with find with relations returns soft-deleted entities #7296
fix: resolve issue with find with relations returns soft-deleted entities #7296
Conversation
02a7ac1
to
2f245e0
Compare
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.
Ideally squash the two commits into one now but otherwise looks good to me 🎉
Actually you should also add tests to verify the functionality, there should already be some examples testing non relation soft deleted items that you can mostly copy paste. |
a2fb2af
to
af2c5c4
Compare
ff6ceb7
to
fe0b221
Compare
…ties This new feature changes the behavior of typeorm to allow avoiding entities that have soft delete close: typeorm#6265
fe0b221
to
9506260
Compare
Tests look reasonable. Strictly this should also be a "feat:" rather than "fix:" but not so important. One thing that will be an issue is that this is essentially a breaking change for current users so not sure how to work around that. |
A bool property for nested soft deletes wouldn't work @nebkat ? something like default would be false, that way maintaining backward compatibility |
That works but it must be covered for both find and query builder, and it must also match the current naming ( |
I propose we add a new flag |
I don't think it should be on |
I was just looking for a way not to affect the current behavior, but I fervently believe that the behavior of the relationships should be the same as the main entity, we can work on updating the documentation of when the join is used and when it is used the soft delete |
Personally I think there should just be a new major release with the breaking change but that doesn't seem to be planned so we have to work around it unfortunately. |
Hey guys. Are there any news on this PR? Looking forward to use it, since I could get rid of a bigger list of workarounds. |
Waiting for @nebkat to deliberate about the best approach... |
@nebkat, following on @caiomestres' train of thought: Find const firstUser = await User.findOne({
where: {
id: 1,
},
withDeletedRelations: false,
}); QueryBuilder const firstUser = await connection
.getRepository(User)
.createQueryBuilder('user')
.withDeletedRelations(false)
.where('user.id = :id', { id: 1 })
.getOne(); Is this something that can be achieved? If so, can you suggest to us where to start? Thanks in advance |
Yes that looks like the ideal solution. |
I don't think we need extra flag at least because it can raise questions like "how to do it with deleted relations but without deleted relations of relations". Also I don't think we need a backward, because without this change current behaviour looks like a bug. Thank you for contribution, I'm going to merge this one. |
when is the next release @pleerock? |
Available in the latest |
Seems to work but When i want to query deleted rows and use: builder.withDeleted(); the query builds as follows: SELECT *
FROM plan
INNER JOIN blank ON blank.id = plan.blank_id
AND (blank.deleted_at IS NULL) <-- still here |
What query in typeom you use? |
@luiseariass i have 2 entities with one-to-one relation @Entity()
class Plan {
@OneToOne(() => Blank, blank => blank.id)
@JoinColumn({ name: 'blank_id' })
blank: Blank;
}
@Entity()
class Blank {
@OneToOne(() => Plan, plan => plan.blank)
plan: Plan;
@DeleteDateColumn()
deleted_at: Date;
} And query builder looks like this const res = await this.manager
.getRepository(Plan)
.createQueryBuilder('plan')
.innerJoinAndSelect(`plan.blank`, 'blank')
.withDeleted()
.getMany(); |
i figure it out, the |
thank you for fix the bug //// |
Any suggestion on how to bring relation deleted without flag? Many soft deletes just exist to continue showing some text of a deleted entity.. |
Description of change
This pull request includes fix for soft delete behavior when including soft deletes relationships.
fix: resolve issue with find with relations returns soft-deleted entities #6265
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #6265