Repository navigation
fix: fix up save with eagerly loaded relation - #11975
Conversation
User descriptionClose #11905 Description of changePull-Request Checklist
PR TypeBug fix Description
Diagram Walkthroughflowchart LR
A["Entity with<br/>non-persistent relations"] -->|"save()"| B["SubjectChangedColumnsComputer"]
B -->|"check persistence flag"| C["Skip disabled relations"]
C -->|"compute only<br/>persistent columns"| D["Successful save"]
|
| Relevant files | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Bug fix |
| ||||||||||
| Tests |
|
commit: |
PR Code Suggestions ✨Latest suggestions up to bc3feac
Previous suggestionsSuggestions up to commit babc9c0
Suggestions up to commit 3328582
Suggestions up to commit d984914
Suggestions up to commit ea1055d
Suggestions up to commit ec10c76
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code Review by Qodo
1. Cascade ignores persistence flag
|
|
Persistent review updated to latest commit 681f0d2 |
|
Persistent review updated to latest commit 38484c6 |
|
Persistent review updated to latest commit ec10c76 |
d984914 to
3328582
Compare
|
Persistent review updated to latest commit ea1055d |
|
Persistent review updated to latest commit 3328582 |
|
Persistent review updated to latest commit d984914 |
|
Persistent review updated to latest commit babc9c0 |
|
Persistent review updated to latest commit bc3feac |
| subject.metadata.relationsWithJoinColumns.forEach((relation) => { | ||
| if (relation.persistenceEnabled === false) return | ||
|
|
||
| // get the related entity from the persisted entity |
There was a problem hiding this comment.
1. Cascade ignores persistence flag 🐞 Bug ✓ Correctness
With the new persistenceEnabled guard, join columns won’t be updated from relations marked persistence:false, but cascade insert/update can still run for those relations. This can persist the related entity while leaving the owning FK unchanged, resulting in surprising partial persistence (relationship not written).
Agent Prompt
### Issue description
`computeDiffRelationalColumns` now skips join-column diffing for relations with `persistenceEnabled === false`. However, `CascadesSubjectBuilder` can still cascade insert/update/soft-remove/recover through those relations, potentially persisting related entities without updating the owning-side FK/join columns, leading to partial/inconsistent persistence.
### Issue Context
Other persistence builders (e.g., many-to-many/one-to-many) already respect `persistenceEnabled` by skipping such relations. Cascades should be consistent with this contract.
### Fix Focus Areas
- src/persistence/subject-builder/CascadesSubjectBuilder.ts[23-46]
- (reference) src/persistence/SubjectChangedColumnsComputer.ts[225-233]
### Suggested change
Add a guard inside the cascades loop:
- If `relation.persistenceEnabled === false`, skip building cascade subjects for that relation.
### Notes
Consider whether the guard should apply to all operation types handled in `CascadesSubjectBuilder` (save/soft-remove/recover), since those are the cascade types supported there.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Close #11905
Description of change
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)