Fields are only cached when withRelation, so they should only be accessed when withRelation.

The result of .Fields() is quite different with and without withRelation.
I assume that if you call it without withRelation, you don't want the
fields that were cached when withRelation was true.
This commit is contained in:
jnfeinstein 2014-11-27 13:59:49 -08:00
parent 13c1b44804
commit a8492826a8
1 changed files with 3 additions and 2 deletions

View File

@ -411,10 +411,11 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField, withRelatio
// Fields get value's fields
func (scope *Scope) Fields(noRelations ...bool) map[string]*Field {
if scope.fields != nil {
var withRelation = len(noRelations) == 0
if withRelation && scope.fields != nil {
return scope.fields
}
var withRelation = len(noRelations) == 0
var fields = map[string]*Field{}
if scope.IndirectValue().IsValid() && scope.IndirectValue().Kind() == reflect.Struct {