-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Cascade remove/set null behavior #278
Comments
E.g. the issue here is that when there is a nullable relationship, the default |
I came across this one. Maybe I just don't understand it correctly. I would expect, that following code should work: // returns 3 items
$existingTags = $target->tags->toCollection()->fetchAll();
// want to keep only 2 of them
$toKeep = [$existingTags[0], $existingTags[2]];
$target->tags->set($toKeep);
$targetRepository->persist($target); But // returns 3 items
$existingTags = $target->tags->toCollection()->fetchAll();
$tagRepo->remove($existingTags[1]);// 👈 this has been added
// want to keep only 2 of them
$toKeep = [$existingTags[0], $existingTags[2]];
$target->tags->set($toKeep);
$targetRepository->persist($target);
// add to line 3 So my question is. Should the first code example work? Or the line with |
Currently, there three options for has many relationships (eg.
Author has many Books
)I see a room for improvement. The main point it is quite easy to forget a cascade behavior, thought, bind a cascade behavior to the nullability is not so much correct.
→
The default behavior could be to throw an exception if a dependency is wired (e.g. something is in relationship), possible cascade values could be (the current)
remove
and (the new one)setNullOnRemove
.Also, I'm thinking about solution to the huge relationship, when it may be convenient to do the cascade in storage layer, then something like removeIgnore would be great and refreshAll()/new identity map would reload the correct db state.
The text was updated successfully, but these errors were encountered: