preserve ObjectID on insert

This commit is contained in:
Sebastian Frank 2019-09-17 10:58:04 +02:00
parent 91ef568a64
commit 64a4178975
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3

View File

@ -41,8 +41,10 @@ func GetCollectionName(m ModelInterface) string {
// PrepareInsert creates new bson id and insert time
func (m *Model) PrepareInsert() {
id := bson.NewObjectId()
m.ID = &id
if m.ID == nil {
id := bson.NewObjectId()
m.ID = &id
}
now := time.Now()
m.InsertTime = &now
m.UpdateTime = &now