From fe3fd9516d97ad47de2b273a34fbbfa697443589 Mon Sep 17 00:00:00 2001 From: Glenn Wilkinson Date: Sat, 24 Oct 2020 11:40:24 +0200 Subject: [PATCH] Fixed search bug to work with MySQL --- models/group.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/group.go b/models/group.go index 3bdc4d93..80de52ce 100644 --- a/models/group.go +++ b/models/group.go @@ -343,7 +343,7 @@ func DeleteTarget(t *Target, gid int64, uid int64) error { return err } // Update group modification date - err = db.Debug().Model(&Group{}).Where("id=?", gid).Update("ModifiedDate", time.Now().UTC()).Error + err = db.Model(&Group{}).Where("id=?", gid).Update("ModifiedDate", time.Now().UTC()).Error return err } @@ -442,10 +442,12 @@ func GetTargets(gid int64, start int64, length int64, search string, order strin // TODO: Rather than having two queries create a partial query and include the search options. Haven't been able to figure out how yet. if search != "" { search = "%" + search + "%" - err = db.Order(order).Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name, targets.position").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Where("targets.first_name LIKE ? OR targets.last_name LIKE ? OR targets.email LIKE ? or targets.position LIKE ?", search, search, search, search, search).Offset(start).Limit(length).Scan(&ts).Error + err = db.Order(order).Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name, targets.position").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Where("targets.first_name LIKE ? OR targets.last_name LIKE ? OR targets.email LIKE ? or targets.position LIKE ?", search, search, search, search).Offset(start).Limit(length).Scan(&ts).Error + } else { err = db.Order(order).Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name, targets.position").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Offset(start).Limit(length).Scan(&ts).Error } + return ts, err }