Fix duplicated deleted condition on FindAndCount (#1619)
Fix duplicated deleted condition on FindAndCount Reviewed-on: https://gitea.com/xorm/xorm/pulls/1619
This commit is contained in:
parent
656cf6e5d6
commit
79cdec7d88
|
@ -61,7 +61,8 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
|
||||||
session.statement.OrderStr = ""
|
session.statement.OrderStr = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.Count(reflect.New(sliceElementType).Interface())
|
// session has stored the conditions so we use `unscoped` to avoid duplicated condition.
|
||||||
|
return session.Unscoped().Count(reflect.New(sliceElementType).Interface())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
|
func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
|
||||||
|
|
|
@ -538,6 +538,21 @@ func TestFindAndCountOneFunc(t *testing.T) {
|
||||||
assert.EqualValues(t, 2, cnt)
|
assert.EqualValues(t, 2, cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFindAndCountOneFuncWithDeleted(t *testing.T) {
|
||||||
|
type CommentWithDeleted struct {
|
||||||
|
Id int `xorm:"pk autoincr"`
|
||||||
|
DeletedAt int64 `xorm:"deleted notnull default(0) index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, prepareEngine())
|
||||||
|
assertSync(t, new(CommentWithDeleted))
|
||||||
|
|
||||||
|
var comments []CommentWithDeleted
|
||||||
|
cnt, err := testEngine.FindAndCount(&comments)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 0, cnt)
|
||||||
|
}
|
||||||
|
|
||||||
type FindMapDevice struct {
|
type FindMapDevice struct {
|
||||||
Deviceid string `xorm:"pk"`
|
Deviceid string `xorm:"pk"`
|
||||||
Status int
|
Status int
|
||||||
|
|
Loading…
Reference in New Issue