improve field filtering for list type parameters of function Data for ForDao models

This commit is contained in:
John Guo
2021-11-15 17:39:23 +08:00
parent 98e5fb1542
commit da7ddd43f5
2 changed files with 5 additions and 4 deletions

View File

@ -78,7 +78,7 @@ func (m *Model) Data(data ...interface{}) *Model {
// If the `data` parameter is defined like `xxxForDao`,
// it then adds `OmitNilData` option for this condition,
// which will filter all nil parameters in `data`.
if isForDaoModel(reflectInfo.OriginValue.Index(0).Type()) {
if isForDaoModel(reflectInfo.OriginValue.Index(0).Elem().Type()) {
model = model.OmitNilData()
model.option |= optionOmitNilDataInternal
}

View File

@ -7,6 +7,7 @@
package gdb_test
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/test/gtest"
"testing"
)
@ -55,13 +56,13 @@ func Test_Model_Insert_Data_LIst_ForDao(t *testing.T) {
Nickname interface{}
CreateTime interface{}
}
data := []UserForDao{
{
data := g.Slice{
UserForDao{
Id: 1,
Passport: "user_1",
Password: "pass_1",
},
{
UserForDao{
Id: 2,
Passport: "user_2",
Password: "pass_2",