Skip to content

Commit

Permalink
WIP - Handle explicit nil sec side rels
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Oct 4, 2024
1 parent 8a0b6b9 commit c78661b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions internal/db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ func (c *collection) save(

relationFieldDescription, isSecondaryRelationID := fieldDescription.GetSecondaryRelationField(c.Definition())
if isSecondaryRelationID {
if val.Value() == nil {
continue //todo - doc
}

primaryId := val.Value().(string)

err = c.patchPrimaryDoc(
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ func getEventsForCreateDoc(s *state, action CreateDoc) map[string]struct{} {

// check for any secondary relation fields that could publish an event
for f, v := range doc.Values() {
if v.Value() == nil {
continue //todo doc
}

field, ok := def.GetFieldByName(f.Name())
if !ok {
continue // ignore unknown field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package one_to_one
import (
"testing"

"github.com/stretchr/testify/require"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand Down Expand Up @@ -119,10 +117,33 @@ func TestMutationCreateOneToOne_WithExplicitNullOnSecondarySide(t *testing.T) {
"published": testUtils.NewDocIndex(0, 0),
},
},
testUtils.Request{
Request: `
query {
Book {
name
author {
name
}
}
}`,
Results: map[string]any{
"Book": []map[string]any{
{
"name": "Secrets at Maple Syrup Farm",
"author": nil,
},
{
"name": "How to Be a Canadian",
"author": map[string]any{
"name": "Will Ferguson",
},
},
},
},
},
},
}

require.Panics(t, func() {
testUtils.ExecuteTestCase(t, test)
})
testUtils.ExecuteTestCase(t, test)
}

0 comments on commit c78661b

Please sign in to comment.