From 18d31564b3d308d29d33b8b9155eb4575aa54d4e Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Fri, 25 Oct 2024 08:27:22 +0800 Subject: [PATCH] fix(client): string operators "contains/does not contains" should handle `null` value (#5509) --- packages/core/client/src/variables/utils/getAction.tsx | 1 + packages/core/database/src/operators/string.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/packages/core/client/src/variables/utils/getAction.tsx b/packages/core/client/src/variables/utils/getAction.tsx index 7910971d2b..94dfc985c8 100644 --- a/packages/core/client/src/variables/utils/getAction.tsx +++ b/packages/core/client/src/variables/utils/getAction.tsx @@ -12,6 +12,7 @@ const TYPE_TO_ACTION = { belongsTo: 'get', hasOne: 'get', belongsToMany: 'list?pageSize=9999', + belongsToArray: 'get', }; export const getAction = (type: string) => { if (process.env.NODE_ENV !== 'production' && !(type in TYPE_TO_ACTION)) { diff --git a/packages/core/database/src/operators/string.ts b/packages/core/database/src/operators/string.ts index be46cd1b47..24d87ec601 100644 --- a/packages/core/database/src/operators/string.ts +++ b/packages/core/database/src/operators/string.ts @@ -16,6 +16,11 @@ function escapeLike(value: string) { export default { $includes(value, ctx) { + if (value === null) { + return { + [Op.is]: null, + }; + } if (Array.isArray(value)) { const conditions = value.map((item) => ({ [isPg(ctx) ? Op.iLike : Op.like]: `%${escapeLike(item)}%`, @@ -32,6 +37,11 @@ export default { }, $notIncludes(value, ctx) { + if (value === null) { + return { + [Op.not]: null, + }; + } if (Array.isArray(value)) { const conditions = value.map((item) => ({ [isPg(ctx) ? Op.notILike : Op.notLike]: `%${escapeLike(item)}%`,