Browse Source

Fix find and count bug (#1622)

Fix find and count bug

Reviewed-on: #1622
tags/v1.0.1
Lunny Xiao 1 week ago
parent
commit
656cf6e5d6
2 changed files with 9 additions and 2 deletions
  1. +1
    -1
      internal/statements/statement.go
  2. +8
    -1
      session_find_test.go

+ 1
- 1
internal/statements/statement.go 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 {


+ 8
- 1
session_find_test.go View File

@@ -525,10 +525,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 {


Loading…
Cancel
Save