diff --git a/pkg/common/adapters/database/bun.go b/pkg/common/adapters/database/bun.go index 3c53e9f..b16c2ba 100644 --- a/pkg/common/adapters/database/bun.go +++ b/pkg/common/adapters/database/bun.go @@ -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 } diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index f6af2e6..8f06f31 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -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{