fix: 复合主键表改为单字段 id 以支持 ent 完整生成

This commit is contained in:
zetaloop
2026-04-24 07:32:52 +08:00
parent c62d743320
commit 5ad579f03c
19 changed files with 324 additions and 82 deletions
@@ -74,6 +74,12 @@ func (_c *ShopPlayersCreate) SetNillableLeftAt(v *time.Time) *ShopPlayersCreate
return _c
}
// SetID sets the "id" field.
func (_c *ShopPlayersCreate) SetID(v int64) *ShopPlayersCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the ShopPlayersMutation object of the builder.
func (_c *ShopPlayersCreate) Mutation() *ShopPlayersMutation {
return _c.mutation
@@ -144,6 +150,11 @@ func (_c *ShopPlayersCreate) sqlSave(ctx context.Context) (*ShopPlayers, error)
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
@@ -151,8 +162,12 @@ func (_c *ShopPlayersCreate) sqlSave(ctx context.Context) (*ShopPlayers, error)
func (_c *ShopPlayersCreate) createSpec() (*ShopPlayers, *sqlgraph.CreateSpec) {
var (
_node = &ShopPlayers{config: _c.config}
_spec = sqlgraph.NewCreateSpec(shopplayers.Table, nil)
_spec = sqlgraph.NewCreateSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.ShopID(); ok {
_spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value)
_node.ShopID = value
@@ -220,6 +235,11 @@ func (_c *ShopPlayersCreateBulk) Save(ctx context.Context) ([]*ShopPlayers, erro
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(id)
}
mutation.done = true
return nodes[i], nil
})