good morning!!!!

Skip to content
Snippets Groups Projects
Commit 492f57bc authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Skip anonymous fields.

parent d1ee10ab
No related branches found
No related tags found
No related merge requests found
...@@ -309,49 +309,57 @@ func (self *T) FieldValues(item interface{}, convertFn func(interface{}) interfa ...@@ -309,49 +309,57 @@ func (self *T) FieldValues(item interface{}, convertFn func(interface{}) interfa
field := item_t.Field(i) field := item_t.Field(i)
if field.PkgPath != "" { if field.PkgPath != `` {
// Field is unexported. // Field is unexported.
continue continue
} }
if field.Anonymous {
// It's an anonymous field. Let's skip it unless it has an explicit
// `db` tag.
if field.Tag.Get(`db`) == `` {
continue
}
}
// Field options. // Field options.
fieldName, fieldOptions := util.ParseTag(field.Tag.Get("db")) fieldName, fieldOptions := util.ParseTag(field.Tag.Get(`db`))
// Deprecated "field" tag. // Deprecated `field` tag.
if deprecatedField := field.Tag.Get("field"); deprecatedField != "" { if deprecatedField := field.Tag.Get(`field`); deprecatedField != `` {
fieldName = deprecatedField fieldName = deprecatedField
} }
// Deprecated "omitempty" tag. // Deprecated `omitempty` tag.
if deprecatedOmitEmpty := field.Tag.Get("omitempty"); deprecatedOmitEmpty != "" { if deprecatedOmitEmpty := field.Tag.Get(`omitempty`); deprecatedOmitEmpty != `` {
fieldOptions["omitempty"] = true fieldOptions[`omitempty`] = true
} }
// Deprecated "inline" tag. // Deprecated `inline` tag.
if deprecatedInline := field.Tag.Get("inline"); deprecatedInline != "" { if deprecatedInline := field.Tag.Get(`inline`); deprecatedInline != `` {
fieldOptions["inline"] = true fieldOptions[`inline`] = true
} }
// Processing field name. // Processing field name.
if fieldName == "-" { if fieldName == `-` {
continue continue
} }
if fieldName == "" { if fieldName == `` {
fieldName = self.ColumnLike(field.Name) fieldName = self.ColumnLike(field.Name)
} }
// Processing tag options. // Processing tag options.
value := item_v.Field(i).Interface() value := item_v.Field(i).Interface()
if fieldOptions["omitempty"] == true { if fieldOptions[`omitempty`] == true {
zero := reflect.Zero(reflect.TypeOf(value)).Interface() zero := reflect.Zero(reflect.TypeOf(value)).Interface()
if value == zero { if value == zero {
continue continue
} }
} }
if fieldOptions["inline"] == true { if fieldOptions[`inline`] == true {
infields, invalues, inerr := self.FieldValues(value, convertFn) infields, invalues, inerr := self.FieldValues(value, convertFn)
if inerr != nil { if inerr != nil {
return nil, nil, inerr return nil, nil, inerr
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment