Fix find and count bug with cols #1826

Merged
lunny merged 1 commits from lunny/fix_find_and_count_cols into master 2020-11-09 04:23:14 +00:00
2 changed files with 10 additions and 0 deletions

View File

@ -552,6 +552,13 @@ func TestFindAndCountOneFunc(t *testing.T) {
assert.EqualValues(t, 1, len(results))
assert.EqualValues(t, 1, cnt)
results = make([]FindAndCountStruct, 0, 1)
cnt, err = testEngine.Where("msg = ?", true).Cols("id", "content", "msg").
Limit(1).FindAndCount(&results)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(results))
assert.EqualValues(t, 1, cnt)
results = make([]FindAndCountStruct, 0, 1)
cnt, err = testEngine.Where("msg = ?", true).Desc("id").
Limit(1).Cols("content").FindAndCount(&results)

View File

@ -57,6 +57,9 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
if session.statement.SelectStr != "" {
session.statement.SelectStr = ""
}
if len(session.statement.ColumnMap) > 0 {
session.statement.ColumnMap = []string{}
}
if session.statement.OrderStr != "" {
session.statement.OrderStr = ""
}