From 4cc13a007d0b1de770c911acea48acaf9962a62d Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Tue, 15 Mar 2022 11:18:52 +0100 Subject: [PATCH] Preload school region --- orm/participant.go | 7 ++++--- orm/school.go | 4 ++-- scripts/export_participants/.gitignore | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/orm/participant.go b/orm/participant.go index 3f4d45ba..ee5503bc 100644 --- a/orm/participant.go +++ b/orm/participant.go @@ -111,11 +111,11 @@ func (model *Participant) exists(db *Database) (*User, error) { if err := db._db.First(&user, &User{Username: model.username()}).Error; err != nil && err != gorm.ErrRecordNotFound { return nil, err } else if err == gorm.ErrRecordNotFound { - log.Printf("User %s doesn't exist", user) + log.Printf("User %s doesn't exist", user.Username) return nil, nil } - log.Printf("User %s exists", user) + log.Printf("User %s exists", user.Username) return &user, nil } @@ -219,7 +219,7 @@ func (model *Participant) Create(db *Database, args map[string]string, w http.Re if err := db._db.First(&school, participant.SchoolID).Error; err != nil { return nil, err } - log.Printf("Check if a participant of the same category exists for school %s", school) + log.Printf("Check if a participant of the same category exists for school %s", school.Name) hasCategory, err := school.HasCategory(db, participant) if err != nil { return nil, err @@ -321,6 +321,7 @@ func (model *Participant) ReadAll(db *Database, args map[string]string, w http.R } if err := db._db. Preload("Category"). + Preload("School.Region"). Preload("School"). Preload("Contests"). Order("lastname"). diff --git a/orm/school.go b/orm/school.go index c08ac169..a67d1100 100644 --- a/orm/school.go +++ b/orm/school.go @@ -67,8 +67,8 @@ type School struct { SelectedRegion map[uint]string `gorm:"-"` AllRegions []*Region `gorm:"-"` - CaptchaID string `gorm:"-",schema:"-"` - CaptchaSolution string `gorm:"-",schema:"-"` + CaptchaID string `gorm:"-" schema:"-"` + CaptchaSolution string `gorm:"-" schema:"-"` mailSender *mail.MailSender } diff --git a/scripts/export_participants/.gitignore b/scripts/export_participants/.gitignore index 3ebacd69..0d7693a7 100644 --- a/scripts/export_participants/.gitignore +++ b/scripts/export_participants/.gitignore @@ -1,2 +1,4 @@ *.csv -*.xlsx \ No newline at end of file +*.xlsx +export_participants +