Clone 方法在v1.0.0版本中不能复用查询条件 #1658

Closed
opened 2020-04-16 10:10:21 +00:00 by xslasd · 4 comments

我在老版本做分页查询里,要显示总数,当前页数据。复用查询条件,使用Clone()方法实现。当我更新xorm版本到v1.0.0版后,复用查询条件失效。

wSql := d.db.NewSession().Context(ctx)
defer wSql.Close()
wSql.Where("AttributeKeyCode=?", AttributeKeyCode)
if Name != "" {
	wSql.Where("Name like ?", "%"+Name+"%")
}
total, err := wSql.Clone().Count(new(model.AttributeVals))
data := make([]*model.AttributeVals, 0)
if err != nil || total == 0 {
	return data, total, err
}
first := (Index - 1) * PageSize
wSql.Limit(PageSize, first)
err = wSql.Find(&data)
return data, total, err

能是实现一个兼容方法?

我在老版本做分页查询里,要显示总数,当前页数据。复用查询条件,使用Clone()方法实现。当我更新xorm版本到v1.0.0版后,复用查询条件失效。 wSql := d.db.NewSession().Context(ctx) defer wSql.Close() wSql.Where("AttributeKeyCode=?", AttributeKeyCode) if Name != "" { wSql.Where("Name like ?", "%"+Name+"%") } total, err := wSql.Clone().Count(new(model.AttributeVals)) data := make([]*model.AttributeVals, 0) if err != nil || total == 0 { return data, total, err } first := (Index - 1) * PageSize wSql.Limit(PageSize, first) err = wSql.Find(&data) return data, total, err 能是实现一个兼容方法?
xslasd started working 2020-04-16 10:11:25 +00:00
Owner

Clone has been removed and will not be taken back.

Please use FindAndCount or you could use builder to create a new condition.

`Clone` has been removed and will not be taken back. Please use `FindAndCount` or you could use `builder` to create a new condition.
lunny closed this issue 2020-04-17 12:08:51 +00:00
lunny added the
wontfix
label 2020-04-17 12:08:59 +00:00

@lunny This should be marked as backwards incompatible in doc. If a newbie checked the documents, he will be misleading

@lunny This should be marked as backwards incompatible in doc. If a newbie checked the documents, he will be misleading
lunny added the
kind
breaking
label 2020-05-15 08:21:38 +00:00
Owner

@k3v1n I think you are right.

@k3v1n I think you are right.

Clone has been removed and will not be taken back.

Please use FindAndCount or you could use builder to create a new condition.

如果是join与多层selec(select)等的复杂语句,还是会使用clone的,使用conds并不满足一些需求,不推荐删除掉该功能。

> `Clone` has been removed and will not be taken back. > > Please use `FindAndCount` or you could use `builder` to create a new condition. 如果是join与多层selec(select)等的复杂语句,还是会使用clone的,使用conds并不满足一些需求,不推荐删除掉该功能。
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1658
No description provided.