COUNT queries were generating incorrect SQL with the table appearing twice

This commit is contained in:
Hein 2025-11-07 10:37:53 +02:00
parent 3b2d05465e
commit eefed23766
2 changed files with 4 additions and 7 deletions

View File

@ -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 {

View File

@ -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 {