Skip to content

Commit af0eb7c

Browse files
committed
Set ID on create with LastInsertedID()
Signed-off-by: David Kröll <[email protected]>
1 parent 96d797a commit af0eb7c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

models/shortcuts.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ func (s *Shortcut) Save() error {
121121
}
122122

123123
func (s *Shortcut) create() error {
124-
_, err := db.Exec(insertShortcut, s.ShortIdentifer, s.RedirectURL, s.RedirectStatus, s.ValidThru, s.UserID)
124+
res, err := db.Exec(insertShortcut, s.ShortIdentifer, s.RedirectURL, s.RedirectStatus, s.ValidThru, s.UserID)
125+
if err != nil {
126+
return err
127+
}
128+
id, err := res.LastInsertId()
129+
if err != nil {
130+
return err
131+
}
132+
s.ID = id
125133
return err
126134
}
127135

0 commit comments

Comments
 (0)