Allow setting fields previously unset, like adding a connection when it was nil in db
This commit is contained in:
@@ -342,6 +342,34 @@ func TestIntegration(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("graph.Update connections when none previously", func(t *testing.T) {
|
||||
cleanFill()
|
||||
one := randomOne()
|
||||
one.Connections = nil
|
||||
err := graph.Insert(ctx, "col", one)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = graph.Update(ctx, "col", one.Query(), operator.Set{Key: entity.Connections + ".newfriend", Value: randomOne()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ones, err = graph.ListCaseInsensitive(ctx, "col", one.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ones) != 1 {
|
||||
t.Fatal(ones)
|
||||
}
|
||||
if len(ones[0].Connections) != 1 {
|
||||
t.Fatal(ones[0].Connections)
|
||||
}
|
||||
if _, ok := ones[0].Connections["newfriend"]; !ok {
|
||||
t.Fatal(ones[0].Connections)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func randomOne() entity.One {
|
||||
|
||||
Reference in New Issue
Block a user