This commit is contained in:
2026-09-04 11:32:12 +05:30
parent fb5d7da81f
commit e51ad615ed
2 changed files with 43 additions and 15 deletions

View File

@@ -168,7 +168,20 @@ func (r *partnerRepository) GetRiderLogs(pid, aid int, fdate, tdate string) ([]m
baseQuery += " AND a.logdate::date = CURRENT_DATE"
}
baseQuery += " GROUP BY a.userid ORDER BY logid ASC"
// GROUP BY the two PRIMARY KEYS, not by a.userid.
//
// The select is "a.*, b.*" — every column of riderlogs and app_users — and
// grouping by a.userid leaves all of them unaggregated: userid is not
// riderlogs' key (logid is), so it does not functionally determine a.logid
// or anything else. Postgres refuses the whole statement, so this endpoint
// answered 500 "column a.logid must appear in the GROUP BY clause" on every
// call it has ever received. Verified on production 2026-09-04.
//
// Grouping by both primary keys is what the query means: one row per LOG
// (the model is RiderlogDetails and the sort is by logid), carrying that
// log's break hours summed. Postgres treats a PK in GROUP BY as determining
// the rest of its table's columns, so "a.*, b.*" is then legal.
baseQuery += " GROUP BY a.logid, b.userid ORDER BY a.logid ASC"
if err := r.db.Raw(baseQuery, args...).Find(&data).Error; err != nil {
return nil, err