From 8e45a20b6a7c56c9cc7dd23450fcce1eb705df57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Z=C3=BCrcher?= Date: Wed, 11 Feb 2026 14:51:07 +0100 Subject: [PATCH] fix key search for []string type --- dbHandler.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dbHandler.go b/dbHandler.go index 1e0dd96..ae0f81e 100644 --- a/dbHandler.go +++ b/dbHandler.go @@ -182,8 +182,22 @@ func (dH *DBHandler) GetByKey(model any, key string, value any, LikeSearch bool, query = query.Preload(relation) } if LikeSearch { + if vals, ok := value.([]string); ok { + subQuery := dH.db + for i, v := range vals { + v = strings.ReplaceAll(v, "*", "%") + if i == 0 { + subQuery = subQuery.Where(key+" LIKE ?", v) + } else { + subQuery = subQuery.Or(key+" LIKE ?", v) + } + } + return query.Where(subQuery).Find(model).Error + } + value = strings.ReplaceAll(fmt.Sprint(value), "*", "%") dH.logger.Debug("getByKey", "find like key "+key+" value "+fmt.Sprint(value)) + fmt.Println(465, "find like key "+key+" value "+fmt.Sprint(value)) return query.Where(key+" LIKE ?", value).Find(model).Error }