bug fixed
This commit is contained in:
parent
26ce60b972
commit
9935922176
|
@ -132,7 +132,7 @@ func (engine *Engine) AutoMapType(t reflect.Type) *Table {
|
||||||
table, ok := engine.Tables[t]
|
table, ok := engine.Tables[t]
|
||||||
if !ok {
|
if !ok {
|
||||||
table = engine.MapType(t)
|
table = engine.MapType(t)
|
||||||
//engine.Tables[t] = table
|
engine.Tables[t] = table
|
||||||
}
|
}
|
||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
18
session.go
18
session.go
|
@ -673,9 +673,13 @@ func (session *Session) InsertOne(bean interface{}) (int64, error) {
|
||||||
if col.IsAutoIncrement && fieldValue.Int() == 0 {
|
if col.IsAutoIncrement && fieldValue.Int() == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if table, ok := session.Engine.Tables[fieldValue.Type()]; ok {
|
if fieldTable, ok := session.Engine.Tables[fieldValue.Type()]; ok {
|
||||||
pkField := reflect.Indirect(fieldValue).FieldByName(table.PKColumn().FieldName)
|
if fieldTable.PrimaryKey != "" {
|
||||||
args = append(args, pkField.Interface())
|
pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumn().FieldName)
|
||||||
|
args = append(args, pkField.Interface())
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
args = append(args, val)
|
args = append(args, val)
|
||||||
}
|
}
|
||||||
|
@ -696,10 +700,16 @@ func (session *Session) InsertOne(bean interface{}) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := res.LastInsertId()
|
id, err := res.LastInsertId()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
if id > 0 && table.PrimaryKey != "" {
|
||||||
|
pkValue := reflect.Indirect(reflect.ValueOf(bean)).FieldByName(table.PKColumn().FieldName)
|
||||||
|
if pkValue.CanSet() {
|
||||||
|
var v interface{} = id
|
||||||
|
pkValue.Set(reflect.ValueOf(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue