refactor: always preload all relations with exists

This commit is contained in:
Derrick Hammer 2024-02-25 09:48:26 -05:00
parent 38375d44d8
commit 3a0c7bdea2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import (
"errors"
"time"
"gorm.io/gorm/clause"
"git.lumeweb.com/LumeWeb/portal/config"
"git.lumeweb.com/LumeWeb/portal/db/models"
@ -414,7 +416,7 @@ func (s AccountServiceDefault) updateAccountInfo(userId uint, info models.User)
func (s AccountServiceDefault) exists(model interface{}, conditions map[string]interface{}) (bool, interface{}, error) {
// Conduct a query with the provided model and conditions
result := s.db.Model(model).Where(conditions).First(model)
result := s.db.Preload(clause.Associations).Model(model).Where(conditions).First(model)
// Check if any rows were found
exists := result.RowsAffected > 0