Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When use the Where condition and The value with Counter other field in ORM Update #2912

Closed
qq413434162 opened this issue Aug 29, 2023 · 1 comment
Labels

Comments

@qq413434162
Copy link

1. What version of Go and system type/arch are you using?

go version go1.20.3 darwin/amd64

2. What version of GoFrame are you using?

GoFrame CLI Tool v2.5.1, https://goframe.org/
GoFrame Version: v2.5.2 in current go.mod
CLI Installed At: /usr/local/bin/gf
CLI Built Detail:
Go Version: go1.20.4
GF Version: v2.5.1
Git Commit: 2023-07-26 21:27:58 e0e0043
Build Time: 2023-07-26 21:32:56

3. Can this issue be re-produced with the latest release?

Yes

4. What did you do?

When use the Where condition and The value with Counter other field in ORM Update

In official example
https://goframe.org/pages/viewpage.action?pageId=1114238

updateData := g.Map{
	"views": &gdb.Counter{ 
        Field: "clicks", 
        Value: 1,
    },
}
// UPDATE `article` SET `views`=`clicks`+1 WHERE `id`=1
result, err := db.Update("article", updateData, "id", 1)

In my example

var (
			columns = dao.Order.Columns()
			ctx     = context.TODO()
		)
		data := g.Map{
			columns.AfterSurplus: &gdb.Counter{
				Field: columns.Amount,
				Value: 0,
			},
		}
		affect, err := dao.Order.
			Ctx(ctx).
			Unscoped().
			Data(data).
			Where(columns.OrderSn, "1242308294272199").
			UpdateAndGetAffected()

		convey.So(err, convey.ShouldBeNil)
		convey.So(affect, convey.ShouldBeGreaterThan, 0)

Stack INFO:

Actual: 'data cannot be empty'

5. What did you expect to see?

UPDATE `order` SET `after_surplus`=amount+0 WHERE `order_sn`='1242308294272199'

6. What did you see instead?

columns.AfterSurplus: gdb.Raw(columns.Amount + "+" + strconv.Itoa(0)),

//columns.AfterSurplus: &gdb.Counter{
//	Field: columns.Amount,
//	Value: 0,
//},
@gqcn
Copy link
Member

gqcn commented Oct 9, 2023

@qq413434162 That is the orm checks the updating increment value 0 is meaningless, it so ignores the updates data. You can change the data as follows:

data := g.Map{
    columns.AfterSurplus: &gdb.Counter{
        Field: columns.Amount,
        Value: 1,
    },
}

@gqcn gqcn added the question label Oct 9, 2023
@gqcn gqcn closed this as completed Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants