Add model inheritance via struct's anonymous fields
This commit is contained in:
parent
65137121ff
commit
7a334f648f
14
scope.go
14
scope.go
@ -237,12 +237,21 @@ func (scope *Scope) Fields() []*Field {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value := indirectValue.FieldByName(fieldStruct.Name)
|
||||||
|
iface := value.Interface()
|
||||||
|
elem := reflect.Indirect(value)
|
||||||
|
|
||||||
|
if fieldStruct.Anonymous && elem.Kind() == reflect.Struct {
|
||||||
|
inner_fields := scope.New(iface).Fields()
|
||||||
|
fields = append(fields, inner_fields...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var field Field
|
var field Field
|
||||||
field.Name = fieldStruct.Name
|
field.Name = fieldStruct.Name
|
||||||
field.DBName = toSnake(fieldStruct.Name)
|
field.DBName = toSnake(fieldStruct.Name)
|
||||||
|
|
||||||
value := indirectValue.FieldByName(fieldStruct.Name)
|
field.Value = iface
|
||||||
field.Value = value.Interface()
|
|
||||||
field.IsBlank = isBlank(value)
|
field.IsBlank = isBlank(value)
|
||||||
|
|
||||||
// Search for primary key tag identifier
|
// Search for primary key tag identifier
|
||||||
@ -257,7 +266,6 @@ func (scope *Scope) Fields() []*Field {
|
|||||||
field.SqlTag = scope.sqlTagForField(&field)
|
field.SqlTag = scope.sqlTagForField(&field)
|
||||||
|
|
||||||
// parse association
|
// parse association
|
||||||
elem := reflect.Indirect(value)
|
|
||||||
typ := elem.Type()
|
typ := elem.Type()
|
||||||
|
|
||||||
switch elem.Kind() {
|
switch elem.Kind() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user