Fix find and count bug #1622

Merged
lunny merged 1 commits from lunny/fix_find_and_count into master 2020-03-23 14:40:01 +00:00
2 changed files with 9 additions and 2 deletions

View File

@ -903,7 +903,7 @@ func (statement *Statement) BuildConds(table *schemas.Table, bean interface{}, i
}
func (statement *Statement) mergeConds(bean interface{}) error {
if !statement.NoAutoCondition {
if !statement.NoAutoCondition && statement.RefTable != nil {
var addedTableName = (len(statement.JoinStr) > 0)
autoCond, err := statement.BuildConds(statement.RefTable, bean, true, true, false, true, addedTableName)
if err != nil {

View File

@ -519,10 +519,17 @@ func TestFindAndCountOneFunc(t *testing.T) {
results = make([]FindAndCountStruct, 0, 1)
cnt, err = testEngine.Where("msg = ?", true).Desc("id").
Limit(1).FindAndCount(&results)
Limit(1).Cols("content").FindAndCount(&results)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(results))
assert.EqualValues(t, 1, cnt)
ids := make([]int64, 0, 2)
tableName := testEngine.GetTableMapper().Obj2Table("FindAndCountStruct")
cnt, err = testEngine.Table(tableName).Limit(1).Cols("id").FindAndCount(&ids)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(ids))
assert.EqualValues(t, 2, cnt)
}
type FindMapDevice struct {