Fixes on Table Name on insert

This commit is contained in:
Hein 2025-11-20 11:49:07 +02:00
parent 640582d508
commit 3d5334002d
2 changed files with 12 additions and 1 deletions

View File

@ -319,6 +319,10 @@ func (b *BunInsertQuery) Model(model interface{}) common.InsertQuery {
}
func (b *BunInsertQuery) Table(table string) common.InsertQuery {
if b.hasModel {
// If model is set, do not override table name
return b
}
b.query = b.query.Table(table)
return b
}

View File

@ -663,7 +663,14 @@ func (h *Handler) handleCreate(ctx context.Context, w common.ResponseWriter, dat
}
// Create insert query
query := tx.NewInsert().Model(modelValue).Table(tableName).Returning("*")
query := tx.NewInsert().Model(modelValue)
// Only set Table() if the model doesn't provide a table name via TableNameProvider
if provider, ok := modelValue.(common.TableNameProvider); !ok || provider.TableName() == "" {
query = query.Table(tableName)
}
query = query.Returning("*")
// Execute BeforeScan hooks - pass query chain so hooks can modify it
itemHookCtx := &HookContext{