From 6ecb7a40d016b2753b60ccb7b20d991d4e703966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 30 Sep 2018 06:48:20 +0200 Subject: [PATCH] associations are not merged when they don't have the same key --- .../AssociationParallelSQLTests.swift | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Tests/GRDBTests/AssociationParallelSQLTests.swift b/Tests/GRDBTests/AssociationParallelSQLTests.swift index 14191b972..a0edee991 100644 --- a/Tests/GRDBTests/AssociationParallelSQLTests.swift +++ b/Tests/GRDBTests/AssociationParallelSQLTests.swift @@ -108,6 +108,60 @@ class AssociationParallelSQLTests: GRDBTestCase { } } + func testParallelTwoIncludingIncludingOtherKey() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try assertEqualSQL(db, A.including(required: A.b).including(required: A.b.forKey("altb")), """ + SELECT "a".*, "b1".*, "b2".* \ + FROM "a" \ + JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ + JOIN "b" "b2" ON ("b2"."id" = "a"."bid") + """) + try assertEqualSQL(db, A.including(required: A.b).including(optional: A.b.forKey("altb")), """ + SELECT "a".*, "b1".*, "b2".* \ + FROM "a" \ + JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ + LEFT JOIN "b" "b2" ON ("b2"."id" = "a"."bid") + """) + try assertEqualSQL(db, A.including(optional: A.b).including(required: A.b.forKey("altb")), """ + SELECT "a".*, "b1".*, "b2".* \ + FROM "a" \ + LEFT JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ + JOIN "b" "b2" ON ("b2"."id" = "a"."bid") + """) + try assertEqualSQL(db, A.including(optional: A.b).including(optional: A.b.forKey("altb")), """ + SELECT "a".*, "b1".*, "b2".* \ + FROM "a" \ + LEFT JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ + LEFT JOIN "b" "b2" ON ("b2"."id" = "a"."bid") + """) + try assertEqualSQL(db, B.including(required: B.a).including(required: B.a.forKey("alta")), """ + SELECT "b".*, "a1".*, "a2".* \ + FROM "b" \ + JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ + JOIN "a" "a2" ON ("a2"."bid" = "b"."id") + """) + try assertEqualSQL(db, B.including(required: B.a).including(optional: B.a.forKey("alta")), """ + SELECT "b".*, "a1".*, "a2".* \ + FROM "b" \ + JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ + LEFT JOIN "a" "a2" ON ("a2"."bid" = "b"."id") + """) + try assertEqualSQL(db, B.including(optional: B.a).including(required: B.a.forKey("alta")), """ + SELECT "b".*, "a1".*, "a2".* \ + FROM "b" \ + LEFT JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ + JOIN "a" "a2" ON ("a2"."bid" = "b"."id") + """) + try assertEqualSQL(db, B.including(optional: B.a).including(optional: B.a.forKey("alta")), """ + SELECT "b".*, "a1".*, "a2".* \ + FROM "b" \ + LEFT JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ + LEFT JOIN "a" "a2" ON ("a2"."bid" = "b"."id") + """) + } + } + func testParallelTwoIncludingIncludingSameAssociation() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in