mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
improve Fields filtering for package gdb
This commit is contained in:
@ -7,7 +7,6 @@
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/util/gutil"
|
||||
"strings"
|
||||
"time"
|
||||
@ -163,15 +162,11 @@ func (c *Core) mappingAndFilterData(schema, table string, data map[string]interf
|
||||
if foundKey != "" {
|
||||
data[foundKey] = dataValue
|
||||
delete(data, dataKey)
|
||||
} else if !filter {
|
||||
if schema != "" {
|
||||
return nil, gerror.Newf(`no column of name "%s" found for table "%s" in schema "%s"`, dataKey, table, schema)
|
||||
}
|
||||
return nil, gerror.Newf(`no column of name "%s" found for table "%s"`, dataKey, table)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Data filtering.
|
||||
// It deletes all key-value pairs that has incorrect field name.
|
||||
if filter {
|
||||
for dataKey, _ := range data {
|
||||
if _, ok := fieldsMap[dataKey]; !ok {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright GoFrame Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
@ -496,6 +496,16 @@ func Test_Model_Update(t *testing.T) {
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
})
|
||||
// Update + Fields(string)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Table(table).Fields("passport").Data(g.Map{
|
||||
"passport": "user_44",
|
||||
"none": "none",
|
||||
}).Where("passport='user_4'").Update()
|
||||
t.Assert(err, nil)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_Clone(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user