Fix find with one key when model key is a string.

This commit is contained in:
Madeorsk 2024-10-17 23:00:35 +02:00
parent 2f93383aa5
commit 0132ec282b
Signed by: Madeorsk
GPG key ID: 677E51CA765BB79F

View file

@ -114,13 +114,27 @@ pub fn Repository(comptime Model: type, comptime TableShape: type, comptime conf
.One => { .One => {
switch (@typeInfo(ptr.child)) { switch (@typeInfo(ptr.child)) {
// Add a whereIn with the array. // 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. // Add a simple condition with the pointed value.
else => try modelQuery.whereValue(keyType, keyName, "=", modelKey.*), else => try modelQuery.whereValue(keyType, keyName, "=", modelKey.*),
} }
}, },
// Add a whereIn with the slice. // 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. // Add a simple condition with the given value.