mirror of https://github.com/go-gorm/gorm.git
fix: `limit(0).offset(0)` return all data (#6191)
Co-authored-by: hanwang <hanwang.7721@bytedance.com>
This commit is contained in:
parent
f0360dccbf
commit
59ca46db3c
|
@ -33,7 +33,7 @@ func (limit Limit) MergeClause(clause *Clause) {
|
|||
clause.Name = ""
|
||||
|
||||
if v, ok := clause.Expression.(Limit); ok {
|
||||
if (limit.Limit == nil || *limit.Limit == 0) && (v.Limit != nil && *v.Limit != 0) {
|
||||
if (limit.Limit == nil || *limit.Limit == 0) && v.Limit != nil {
|
||||
limit.Limit = v.Limit
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@ func TestLimit(t *testing.T) {
|
|||
[]clause.Interface{clause.Select{}, clause.From{}, clause.Limit{Limit: &limit0}},
|
||||
"SELECT * FROM `users` LIMIT 0", nil,
|
||||
},
|
||||
{
|
||||
[]clause.Interface{clause.Select{}, clause.From{}, clause.Limit{Limit: &limit0}, clause.Limit{Offset: 0}},
|
||||
"SELECT * FROM `users` LIMIT 0", nil,
|
||||
},
|
||||
{
|
||||
[]clause.Interface{clause.Select{}, clause.From{}, clause.Limit{Offset: 20}},
|
||||
"SELECT * FROM `users` OFFSET 20", nil,
|
||||
|
|
Loading…
Reference in New Issue