mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 23:28:44 +05:00
Fix GORM pagination with zero limit/offset
Previously, q.Limit(0) was always set, causing GORM to return no records since limit=0 was interpreted as "get 0 records" rather than "no limit". Now we only set limit and offset when they're > 0, which makes pagination behave correctly with default values.
This commit is contained in:
committed by
Dan Christian Bogos
parent
961f132efb
commit
2a85e371a2
@@ -218,8 +218,12 @@ func (sqls *SQLStorage) GetCDRs(ctx *context.Context, qryFltr []*Filter, opts ma
|
||||
if maxItems < limit+offset {
|
||||
return nil, fmt.Errorf("sum of limit and offset exceeds maxItems")
|
||||
}
|
||||
q = q.Limit(limit)
|
||||
q = q.Offset(offset)
|
||||
if limit > 0 {
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
if offset > 0 {
|
||||
q = q.Offset(offset)
|
||||
}
|
||||
|
||||
// Execute query
|
||||
results := make([]*utils.CDRSQLTable, 0)
|
||||
|
||||
Reference in New Issue
Block a user