-
Notifications
You must be signed in to change notification settings - Fork 72
Discussion: The need for helper methods which make removing relationships possible #219
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
Comments
It might also be worth mentioning that if N:M relationships are to bee implemented soon, there should be a way to remove them. As doing this by deleting the desired element from the slice is not an option, this methods could provide the solutions to both problems easily. |
Issuing a query that explicitly updates the relation column could be used to delete the relation. I guess you can assume that a programmer who explicitly states a Another idea is to allow checking the relation key after some query that does not fetch the relation. I might want to get the Just some thoughts :) |
So, if I understood properly, your first suggestion is to make The main advantage of this approach is we won't need to implement new functions, just tweak existing ones. However, this can also be a bit less intuitive. It just doesn't come to your mind that I like to think I'm good at naming things, but I can't think of anything but Btw, I think that reading (but not writing) the ID can be done with To sum up, yes, we could tweak |
Now that #211 is fixed and Save() does not delete the relations of fields set to
nil
, the need of direct relationship manipulation may arise in some scenarios.Consider, for example, the following two entities
If our person
donald
is a very bad guy, he might want to abandon his dog. Settingsnoopy.Owner
to nil won't actually remove the relation, just like removingsnoopy
fromdonald.Pets
and then issuing an update.Since raw queries are something that (at least I think) should be avoided, giving DogStore functions to manipulate the owner directly (
SetOwner(p *Person, d... *Dog)
?) might be a good thing.This example may look as a corner case, as often models cannot exist without relations, but for more complex models which are expensive to create, or those applications which choose to implement some sort of "soft delete" It might be a good thing for kallax to have.
The text was updated successfully, but these errors were encountered: