-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow primary field declarations on one-many (#2796)
## Relevant issue(s) Resolves #961 ## Description Allows primary field declarations on one side of one-many. Declaring it as primary doesn't do anything, but there is no reason it shouldn't be permitted and it definitely shouldn't have errored the way it did.
- Loading branch information
1 parent
2aba842
commit e5ff02c
Showing
3 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package schema | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestSchemaOneMany_Primary(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type User { | ||
name: String | ||
dogs: [Dog] | ||
} | ||
type Dog { | ||
name: String | ||
owner: User @primary | ||
} | ||
`, | ||
ExpectedResults: []client.CollectionDescription{ | ||
{ | ||
Name: immutable.Some("User"), | ||
Fields: []client.CollectionFieldDescription{ | ||
{ | ||
Name: "_docID", | ||
}, | ||
{ | ||
Name: "dogs", | ||
ID: 1, | ||
Kind: immutable.Some[client.FieldKind](client.ObjectArrayKind("Dog")), | ||
RelationName: immutable.Some("dog_user"), | ||
}, | ||
{ | ||
Name: "name", | ||
ID: 2, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: immutable.Some("Dog"), | ||
Fields: []client.CollectionFieldDescription{ | ||
{ | ||
Name: "_docID", | ||
}, | ||
{ | ||
Name: "name", | ||
ID: 1, | ||
}, | ||
{ | ||
Name: "owner", | ||
ID: 2, | ||
Kind: immutable.Some[client.FieldKind](client.ObjectKind("User")), | ||
RelationName: immutable.Some("dog_user"), | ||
}, | ||
{ | ||
Name: "owner_id", | ||
ID: 3, | ||
Kind: immutable.Some[client.FieldKind](client.ScalarKind(client.FieldKind_DocID)), | ||
RelationName: immutable.Some("dog_user"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |