From 0132ec282b94f9fca9a1bb71120de896212f50de Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Thu, 17 Oct 2024 23:00:35 +0200 Subject: [PATCH] Fix find with one key when model key is a string. --- src/repository.zig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/repository.zig b/src/repository.zig index 47d9f9d..d09b8a4 100644 --- a/src/repository.zig +++ b/src/repository.zig @@ -114,13 +114,27 @@ pub fn Repository(comptime Model: type, comptime TableShape: type, comptime conf .One => { switch (@typeInfo(ptr.child)) { // Add a whereIn with the array. - .Array => try modelQuery.whereIn(keyType, keyName, modelKey), + .Array => { + if (ptr.child == u8) + // If the child is a string, use it as a simple value. + try modelQuery.whereValue(KeyType, keyName, "=", modelKey) + else + // Otherwise, use it as an array. + try modelQuery.whereIn(keyType, keyName, modelKey); + }, // Add a simple condition with the pointed value. else => try modelQuery.whereValue(keyType, keyName, "=", modelKey.*), } }, // Add a whereIn with the slice. - else => try modelQuery.whereIn(keyType, keyName, modelKey), + else => { + if (ptr.child == u8) + // If the child is a string, use it as a simple value. + try modelQuery.whereValue(KeyType, keyName, "=", modelKey) + else + // Otherwise, use it as an array. + try modelQuery.whereIn(keyType, keyName, modelKey); + }, } }, // Add a simple condition with the given value.