From 662a0cdd39559716a25c8565db0d29397657486b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 17 Jan 2022 18:20:37 +0000 Subject: [PATCH] Adding SQL test case for SQL relationship filtering. --- .../server/src/integrations/tests/sql.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/server/src/integrations/tests/sql.spec.js b/packages/server/src/integrations/tests/sql.spec.js index 64cdda215f..6ef82f0113 100644 --- a/packages/server/src/integrations/tests/sql.spec.js +++ b/packages/server/src/integrations/tests/sql.spec.js @@ -119,6 +119,22 @@ describe("SQL query builder", () => { }) }) + it("should allow filtering on a related field", () => { + const query = sql._query(generateReadJson({ + filters: { + equal: { + age: 10, + "task.name": "task 1", + }, + }, + })) + // order of bindings changes because relationship filters occur outside inner query + expect(query).toEqual({ + bindings: [10, limit, "task 1"], + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age" = $1 limit $2) as "${TABLE_NAME}" where "task"."name" = $3` + }) + }) + it("should test an create statement", () => { const query = sql._query(generateCreateJson(TABLE_NAME, { name: "Michael",