From 58a36ec5091c3ee1db3614ac1811cb5cde24e26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 11 Jan 2020 19:00:57 +0100 Subject: [PATCH] Add including(all:) test fixed by ebdfa9e52a8652b6aa2d3fb16f4ec4d3c3932f37 --- .../AssociationHasManySQLTests.swift | 2 +- .../AssociationHasManyThroughSQLTests.swift | 2 +- .../AssociationPrefetchingSQLTests.swift | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Tests/GRDBTests/AssociationHasManySQLTests.swift b/Tests/GRDBTests/AssociationHasManySQLTests.swift index 28b628994..99443d3fb 100644 --- a/Tests/GRDBTests/AssociationHasManySQLTests.swift +++ b/Tests/GRDBTests/AssociationHasManySQLTests.swift @@ -765,7 +765,7 @@ class AssociationHasManySQLTests: GRDBTestCase { } } - func testJoinedAssociation() throws { + func testAssociationFilteredByOtherAssociation() throws { struct Toy: TableRecord { } struct Child: TableRecord { static let toy = hasOne(Toy.self) diff --git a/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift b/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift index 2c20efee3..269b1885e 100644 --- a/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift +++ b/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift @@ -314,7 +314,7 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase { } } - func testJoinedAssociation() throws { + func testAssociationFilteredByOtherAssociation() throws { struct Pet: TableRecord { static let child = belongsTo(Child.self) } diff --git a/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift b/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift index 8d4d38f16..091af750d 100644 --- a/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift +++ b/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift @@ -1537,4 +1537,39 @@ class AssociationPrefetchingSQLTests: GRDBTestCase { } } } + + func testAssociationFilteredByOtherAssociation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany( + D.self, + through: A.hasMany(C.self) + .joining(required: C.belongsTo(A.self).filter(sql: "1")), + using: C.hasMany(D.self)) + .orderByPrimaryKey()) + .filter(sql: "1 + 1") + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") && !$0.contains("sqlite_") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" WHERE 1 + 1 ORDER BY "cola1" + """, + """ + SELECT "d".*, "c"."colc2" AS "grdb_colc2" \ + FROM "d" \ + JOIN "c" ON ("c"."colc1" = "d"."cold2") AND ("c"."colc2" IN (1, 2, 3)) \ + JOIN "a" ON ("a"."cola1" = "c"."colc2") AND (1) \ + ORDER BY "d"."cold1" + """]) + } + } + } }