Refact scope Fields

This commit is contained in:
Jinzhu 2014-07-30 15:15:23 +08:00
parent 0d3085393e
commit 9b3be66a77
1 changed files with 10 additions and 16 deletions

View File

@ -315,24 +315,18 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) *Field {
}
// Fields get value's fields
func (scope *Scope) Fields() []*Field {
indirectValue := scope.IndirectValue()
fields := []*Field{}
if !indirectValue.IsValid() {
return fields
}
scopeTyp := indirectValue.Type()
for i := 0; i < scopeTyp.NumField(); i++ {
fieldStruct := scopeTyp.Field(i)
if !ast.IsExported(fieldStruct.Name) {
continue
func (scope *Scope) Fields() (fields []*Field) {
if scope.IndirectValue().IsValid() {
scopeTyp := scope.IndirectValue().Type()
for i := 0; i < scopeTyp.NumField(); i++ {
fieldStruct := scopeTyp.Field(i)
if !ast.IsExported(fieldStruct.Name) {
continue
}
fields = append(fields, scope.fieldFromStruct(fieldStruct))
}
fields = append(fields, scope.fieldFromStruct(fieldStruct))
}
return fields
return
}
// Raw set sql