associations are not merged when they don't have the same key

This commit is contained in:
Gwendal Roué committed 2018-09-30 06:48:20 +02:00
1 parent 52ec6c6cd2
commit 6ecb7a40d0
1 file changed
+54
@@ -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