Description
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
type Person struct {
kallax.Model
Name string
Dogs []*Dog
}
type Dog struct {
kallax.Model
Name string
Owner *Person
}
If our person donald
is a very bad guy, he might want to abandon his dog. Setting snoopy.Owner
to nil won't actually remove the relation, just like removing snoopy
from donald.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.