mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 11:18:02 +08:00
improve field filtering for list type parameters of function Data for ForDao models
This commit is contained in:
parent
f99b037c60
commit
98e5fb1542
@ -80,6 +80,7 @@ func (m *Model) Data(data ...interface{}) *Model {
|
||||
// which will filter all nil parameters in `data`.
|
||||
if isForDaoModel(reflectInfo.OriginValue.Index(0).Type()) {
|
||||
model = model.OmitNilData()
|
||||
model.option |= optionOmitNilDataInternal
|
||||
}
|
||||
}
|
||||
list := make(List, reflectInfo.OriginValue.Len())
|
||||
|
@ -7,12 +7,14 @@
|
||||
package gdb
|
||||
|
||||
const (
|
||||
optionOmitNil = optionOmitNilWhere | optionOmitNilData
|
||||
optionOmitEmpty = optionOmitEmptyWhere | optionOmitEmptyData
|
||||
optionOmitEmptyWhere = 1 << iota // 8
|
||||
optionOmitEmptyData // 16
|
||||
optionOmitNilWhere // 32
|
||||
optionOmitNilData // 64
|
||||
optionOmitNil = optionOmitNilWhere | optionOmitNilData
|
||||
optionOmitEmpty = optionOmitEmptyWhere | optionOmitEmptyData
|
||||
optionOmitNilDataInternal = optionOmitNilData | optionOmitNilDataList // this option is used internally only for ForDao feature.
|
||||
optionOmitEmptyWhere = 1 << iota // 8
|
||||
optionOmitEmptyData // 16
|
||||
optionOmitNilWhere // 32
|
||||
optionOmitNilData // 64
|
||||
optionOmitNilDataList // 128
|
||||
)
|
||||
|
||||
// OmitEmpty sets optionOmitEmpty option for the model, which automatically filers
|
||||
|
@ -87,8 +87,14 @@ func (m *Model) filterDataForInsertOrUpdate(data interface{}) (interface{}, erro
|
||||
var err error
|
||||
switch value := data.(type) {
|
||||
case List:
|
||||
var (
|
||||
omitEmpty bool
|
||||
)
|
||||
if m.option&optionOmitNilDataList > 0 {
|
||||
omitEmpty = true
|
||||
}
|
||||
for k, item := range value {
|
||||
value[k], err = m.doMappingAndFilterForInsertOrUpdateDataMap(item, false)
|
||||
value[k], err = m.doMappingAndFilterForInsertOrUpdateDataMap(item, omitEmpty)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user