mirror of
https://github.com/ent/ent.git
synced 2026-04-27 21:20:51 +03:00
entc/gen: allow setting unique fields with default values of type function (#610)
Fixed #609
This commit is contained in:
@@ -575,7 +575,7 @@ func (t *Type) checkField(tf *Field, f *load.Field) (err error) {
|
||||
err = fmt.Errorf("invalid type for field %s", f.Name)
|
||||
case f.Nillable && !f.Optional:
|
||||
err = fmt.Errorf("nillable field %q must be optional", f.Name)
|
||||
case f.Unique && f.Default:
|
||||
case f.Unique && f.Default && f.Info.Type != field.TypeUUID:
|
||||
err = fmt.Errorf("unique field %q cannot have default value", f.Name)
|
||||
case t.fields[f.Name] != nil:
|
||||
err = fmt.Errorf("field %q redeclared for type %q", f.Name, t.Name)
|
||||
|
||||
@@ -15,7 +15,7 @@ var (
|
||||
// BlobsColumns holds the columns for the "blobs" table.
|
||||
BlobsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "uuid", Type: field.TypeUUID},
|
||||
{Name: "uuid", Type: field.TypeUUID, Unique: true},
|
||||
{Name: "blob_parent", Type: field.TypeUUID, Unique: true, Nullable: true},
|
||||
}
|
||||
// BlobsTable holds the schema information for the "blobs" table.
|
||||
|
||||
@@ -23,7 +23,8 @@ func (Blob) Fields() []ent.Field {
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New),
|
||||
field.UUID("uuid", uuid.UUID{}).
|
||||
Default(uuid.New),
|
||||
Default(uuid.New).
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user