From 79e7c797beea54bfc9dc1cb0141a7520ff941b4d Mon Sep 17 00:00:00 2001 From: j2gg0s Date: Mon, 24 Jan 2022 19:56:54 +0800 Subject: [PATCH] feat(insert): get last insert id only with pk support auto increment --- query_insert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query_insert.go b/query_insert.go index 7a826b62f..dc5a45760 100644 --- a/query_insert.go +++ b/query_insert.go @@ -588,7 +588,7 @@ func (q *InsertQuery) afterInsertHook(ctx context.Context) error { } func (q *InsertQuery) tryLastInsertID(res sql.Result, dest []interface{}) error { - if q.db.features.Has(feature.Returning) || q.table == nil || len(q.table.PKs) != 1 { + if q.db.features.Has(feature.Returning) || q.table == nil || len(q.table.PKs) != 1 || !q.table.PKs[0].AutoIncrement { return nil }