mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
ent/field: force optional on nillable field
Reviewed By: alexsn Differential Revision: D16757719 fbshipit-source-id: 813e10b8b4b1744e7ab68f4513722f66911cdef3
This commit is contained in:
committed by
Facebook Github Bot
parent
71725de3d7
commit
f2411742ae
@@ -17,7 +17,7 @@ var (
|
||||
Name: "T1",
|
||||
Fields: []*load.Field{
|
||||
{Name: "age", Type: field.TypeInt, Optional: true},
|
||||
{Name: "expired_at", Type: field.TypeTime, Nillable: true},
|
||||
{Name: "expired_at", Type: field.TypeTime, Nillable: true, Optional: true},
|
||||
{Name: "name", Type: field.TypeString, Default: true},
|
||||
},
|
||||
Edges: []*load.Edge{
|
||||
@@ -77,7 +77,7 @@ func TestNewGraph(t *testing.T) {
|
||||
for i, typ := range []string{"int", "time.Time", "string"} {
|
||||
require.Equal(typ, t1.Fields[i].Type.String())
|
||||
}
|
||||
for i, optional := range []bool{true, false, false} {
|
||||
for i, optional := range []bool{true, true, false} {
|
||||
require.Equal(optional, t1.Fields[i].Optional)
|
||||
}
|
||||
for i, nullable := range []bool{false, true, false} {
|
||||
@@ -157,7 +157,7 @@ func TestGraph_Gen(t *testing.T) {
|
||||
Name: "T1",
|
||||
Fields: []*load.Field{
|
||||
{Name: "age", Type: field.TypeInt, Optional: true},
|
||||
{Name: "expired_at", Type: field.TypeTime, Nillable: true},
|
||||
{Name: "expired_at", Type: field.TypeTime, Nillable: true, Optional: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
},
|
||||
Edges: []*load.Edge{
|
||||
|
||||
@@ -110,6 +110,9 @@ func NewType(c Config, schema *load.Schema) (*Type, error) {
|
||||
if !f.Type.Valid() {
|
||||
return nil, fmt.Errorf("invalid type for field %s", f.Name)
|
||||
}
|
||||
if f.Nillable && !f.Optional {
|
||||
return nil, fmt.Errorf("nillable field %q must be optional", f.Name)
|
||||
}
|
||||
typ.Fields = append(typ.Fields, &Field{
|
||||
def: f,
|
||||
Name: f.Name,
|
||||
|
||||
@@ -102,7 +102,7 @@ func schemaGo() (*asset, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "schema.go", size: 2637, mode: os.FileMode(420), modTime: time.Unix(1565179921, 0)}
|
||||
info := bindataFileInfo{name: "schema.go", size: 2637, mode: os.FileMode(420), modTime: time.Unix(1565536164, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user