8000 Discussion: The need for helper methods which make removing relationships possible · Issue #219 · src-d/go-kallax · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Discussion: The need for helper methods which make removing relationships possible #219
Open
@nadiamoe

Description

@nadiamoe

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0