From eefed23766fbff312bf3e29fa14262a41d30db8e Mon Sep 17 00:00:00 2001 From: Hein Date: Fri, 7 Nov 2025 10:37:53 +0200 Subject: [PATCH] COUNT queries were generating incorrect SQL with the table appearing twice --- pkg/resolvespec/handler.go | 7 ++----- pkg/restheadspec/handler.go | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/resolvespec/handler.go b/pkg/resolvespec/handler.go index 67c16ff..92a1098 100644 --- a/pkg/resolvespec/handler.go +++ b/pkg/resolvespec/handler.go @@ -165,13 +165,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st return } - // Create a pointer to the model type for database operations - modelPtr := reflect.New(modelType).Interface() - logger.Info("Reading records from %s.%s", schema, entity) - query := h.db.NewSelect().Model(modelPtr) - query = query.Table(tableName) + // Use Table() with the resolved table name (don't use Model() as it would add the table twice) + query := h.db.NewSelect().Table(tableName) // Apply column selection if len(options.Columns) > 0 { diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index fbc0607..4128fcc 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -197,8 +197,8 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st logger.Info("Reading records from %s.%s", schema, entity) - query := h.db.NewSelect().Model(modelPtr) - query = query.Table(tableName) + // Use Table() with the resolved table name (don't use Model() as it would add the table twice) + query := h.db.NewSelect().Table(tableName) // Apply column selection if len(options.Columns) > 0 {