fix key search for []string type

This commit is contained in:
Adrian Zürcher
2026-02-11 14:51:07 +01:00
parent dd4840b694
commit 8e45a20b6a

View File

@@ -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
}