Skip to content

Commit 76bbf33

Browse files
author
Hein
committed
Fixed SingleRecordAsObject true when handleRead with no id
1 parent 02c9b96 commit 76bbf33

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

pkg/resolvespec/handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
199199
// Apply column selection
200200
if len(options.Columns) > 0 {
201201
logger.Debug("Selecting columns: %v", options.Columns)
202-
query = query.Column(options.Columns...)
202+
for _, col := range options.Columns {
203+
query = query.Column(reflection.ExtractSourceColumn(col))
204+
}
203205
}
204206

205207
if len(options.ComputedColumns) > 0 {

pkg/restheadspec/handler.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
213213
tableName := GetTableName(ctx)
214214
model := GetModel(ctx)
215215

216+
if id == "" {
217+
options.SingleRecordAsObject = false
218+
}
219+
216220
// Execute BeforeRead hooks
217221
hookCtx := &HookContext{
218222
Context: ctx,
@@ -299,7 +303,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
299303
// Apply column selection
300304
if len(options.Columns) > 0 {
301305
logger.Debug("Selecting columns: %v", options.Columns)
302-
query = query.Column(options.Columns...)
306+
for _, col := range options.Columns {
307+
query = query.Column(reflection.ExtractSourceColumn(col))
308+
}
309+
303310
}
304311

305312
// Apply expand (Just expand to Preload for now)
@@ -652,7 +659,6 @@ func (h *Handler) applyPreloadWithRecursion(query common.SelectQuery, preload co
652659
sq = sq.Order(fmt.Sprintf("%s %s", sort.Column, sort.Direction))
653660
}
654661
}
655-
656662

657663
// Apply WHERE clause
658664
if len(preload.Where) > 0 {

pkg/restheadspec/headers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request, model interface{}) E
267267
h.resolveRelationNamesInOptions(&options, model)
268268
}
269269

270-
//Always sort according to the primary key if no sorting is specified
270+
// Always sort according to the primary key if no sorting is specified
271271
if len(options.Sort) == 0 {
272272
pkName := reflection.GetPrimaryKeyName(model)
273273
options.Sort = []common.SortOption{{Column: pkName, Direction: "ASC"}}

0 commit comments

Comments
 (0)