mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: skip checking required fields with db-based default values (#3204)
This commit is contained in:
@@ -8,8 +8,10 @@ package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
@@ -23,6 +25,12 @@ type BlogCreate struct {
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetOid sets the "oid" field.
|
||||
func (bc *BlogCreate) SetOid(i int) *BlogCreate {
|
||||
bc.mutation.SetOid(i)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (bc *BlogCreate) SetID(i int) *BlogCreate {
|
||||
bc.mutation.SetID(i)
|
||||
@@ -78,6 +86,12 @@ func (bc *BlogCreate) ExecX(ctx context.Context) {
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (bc *BlogCreate) check() error {
|
||||
switch bc.driver.Dialect() {
|
||||
case dialect.MySQL, dialect.SQLite:
|
||||
if _, ok := bc.mutation.Oid(); !ok {
|
||||
return &ValidationError{Name: "oid", err: errors.New(`entv2: missing required field "Blog.oid"`)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -116,6 +130,10 @@ func (bc *BlogCreate) createSpec() (*Blog, *sqlgraph.CreateSpec) {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := bc.mutation.Oid(); ok {
|
||||
_spec.SetField(blog.FieldOid, field.TypeInt, value)
|
||||
_node.Oid = value
|
||||
}
|
||||
if nodes := bc.mutation.AdminsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
Reference in New Issue
Block a user