Merge 75ec40de67154d1354e8237c50467cbe0f33a154 into b3d62fafc3d98be04630e76a858e0e3e819bec6a

This commit is contained in:
CodeRushing 2015-06-08 01:30:39 +00:00
commit 8320149214
2 changed files with 8 additions and 4 deletions

View File

@ -40,6 +40,7 @@ type StructField struct {
Tag reflect.StructTag Tag reflect.StructTag
Struct reflect.StructField Struct reflect.StructField
IsForeignKey bool IsForeignKey bool
IsAutoIncrement bool
Relationship *Relationship Relationship *Relationship
} }
@ -148,6 +149,10 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
field.HasDefaultValue = true field.HasDefaultValue = true
} }
if _, ok := sqlSettings["AUTO_INCREMENT"]; ok {
field.IsAutoIncrement = true
}
if value, ok := gormSettings["COLUMN"]; ok { if value, ok := gormSettings["COLUMN"]; ok {
field.DBName = value field.DBName = value
} else { } else {

View File

@ -112,12 +112,11 @@ func (scope *Scope) HasError() bool {
func (scope *Scope) PrimaryField() *Field { func (scope *Scope) PrimaryField() *Field {
if primaryFields := scope.GetModelStruct().PrimaryFields; len(primaryFields) > 0 { if primaryFields := scope.GetModelStruct().PrimaryFields; len(primaryFields) > 0 {
if len(primaryFields) > 1 { for i := 0; i < len(primaryFields); i++ {
if field, ok := scope.Fields()["id"]; ok { if primaryFields[i].IsAutoIncrement {
return field return scope.Fields()[primaryFields[i].DBName]
} }
} }
return scope.Fields()[primaryFields[0].DBName]
} }
return nil return nil
} }