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
CAY-2853 Incorrect deletion of entities from flattened attributes #614
CAY-2853 Incorrect deletion of entities from flattened attributes #614
Conversation
bb796b9
to
ffa2791
Compare
This PR is ready for review please. |
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.
@Jugen Thanks for the PR! I got some thoughts on how we may improve it a bit.
cayenne/src/main/java/org/apache/cayenne/access/ObjectStore.java
Outdated
Show resolved
Hide resolved
cayenne/src/main/java/org/apache/cayenne/access/flush/RootRowOpProcessor.java
Outdated
Show resolved
Hide resolved
cayenne/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
Outdated
Show resolved
Hide resolved
cayenne/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
Show resolved
Hide resolved
ffa2791
to
4189308
Compare
Have made all the changes as requested. Note that the changes to |
4189308
to
338920e
Compare
Updated release notes and squashed commits for this PR. |
Now that this has been merged are there steps that I must take to back port this as previously suggested ? |
@Jugen I'll try to just cherry-pick this commit, and hope that it'll just apply. |
When deleting an ObjEntity with flattened attributes Cayenne deletes the related DB attribute's row as well.
So if we have for example an ObjEntity "FlatPainting" with flattened attribute "galleryName". If we then delete a "FlatPainting" then the associated gallery will also be deleted, leaving all other paintings at that gallery without a valid Gallery link.
Furthermore if we add to our "FlatPainting" a "gallery" relationship attribute with delete rule Deny, the gallery was still being deleted.
The original intention was for something like a "PaintingFull" ObjEntity having all painting attributes and a flattened attribute to "PaintingInfo" as well, where the relationship is 1:1. In this case it makes sense that deleting a "PaintingFull" should also delete its associated PaintingInfo record.
In this PR a check has been added so that reverse toMany relationships are protected from deletion,
and if a relevant ObjRelationship is present then deletions are deferred to it instead.