master
Evan Chen 2022-01-09 16:48:10 +08:00
parent 03cc592768
commit 72a783bdd3
1 changed files with 10 additions and 0 deletions

View File

@ -37,6 +37,16 @@ func (e *Event) BeforeSave(tx *gorm.DB) (err error) {
tx.Raw("select name from calendars where id = ?", e.CalendarID).Scan(&loc)
e.Location = loc
}
// test for collide
cnt := 0
db.Raw(`select count(*) from events e where
(? >= "start" and ? <= "end" )
or
(? >= "start" and ? <= "end" )
and calendar_id = ?`,
e.End, e.End, e.Start, e.Start, e.CalendarID).Scan(&cnt)
return
}