From 64a41789756ddd6be2fe563fbfe634bba6139d6c Mon Sep 17 00:00:00 2001
From: Sebastian Frank <frank@basiskonfiguration.de>
Date: Tue, 17 Sep 2019 10:58:04 +0200
Subject: [PATCH] preserve ObjectID on insert

---
 interface.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/interface.go b/interface.go
index 593777b..ec8ddf3 100644
--- a/interface.go
+++ b/interface.go
@@ -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