-
Notifications
You must be signed in to change notification settings - Fork 8
/
relationship_test.go
39 lines (29 loc) · 840 Bytes
/
relationship_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package pqt_test
import (
"testing"
"github.com/piotrkowalczuk/pqt"
)
func TestWithColumnName(t *testing.T) {
icn := "author"
t1 := pqt.NewTable("user").AddColumn(pqt.NewColumn("id", pqt.TypeSerial(), pqt.WithPrimaryKey()))
t2 := pqt.NewTable("comment")
t2.AddRelationship(pqt.OneToOne(t1, pqt.WithColumnName(icn)))
if len(t1.InversedRelationships) != 0 {
t.Fatalf("user table should have exactly 0 relationship, got %d", len(t1.InversedRelationships))
}
if len(t2.OwnedRelationships) != 1 {
t.Fatalf("comment table should have exactly 1 relationship, got %d", len(t2.OwnedRelationships))
}
var exists bool
for _, c := range t2.Columns {
if c.Name == icn {
exists = true
break
}
}
if !exists {
t.Errorf("comment table should have column with name %s", icn)
}
}
func TestManyToMany(t *testing.T) {
}