                 t.column("bId").references("b")
             }
             
-            do {
-                for request in [
-                    A.including(optional: A.d1),
-                    A.including(optional: A.d2)]
-                {
-                    try assertEqualSQL(db, request, """
-                        SELECT "a".*, "d".* \
-                        FROM "a" \
-                        LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
-                        LEFT JOIN "c" ON ("c"."id" = "b"."cId") \
-                        LEFT JOIN "d" ON ("d"."cId" = "c"."id")
-                        """)
-                }
-                for request in [
-                    A.including(required: A.d1),
-                    A.including(required: A.d2)]
-                {
-                    try assertEqualSQL(db, request, """
-                        SELECT "a".*, "d".* \
-                        FROM "a" \
-                        JOIN "b" ON ("b"."id" = "a"."bId") \
-                        JOIN "c" ON ("c"."id" = "b"."cId") \
-                        JOIN "d" ON ("d"."cId" = "c"."id")
-                        """)
-                }
-                for request in [
-                    A.joining(optional: A.d1),
-                    A.joining(optional: A.d2)]
-                {
-                    try assertEqualSQL(db, request, """
-                        SELECT "a".* \
-                        FROM "a" \
-                        LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
-                        LEFT JOIN "c" ON ("c"."id" = "b"."cId") \
-                        LEFT JOIN "d" ON ("d"."cId" = "c"."id")
-                        """)
-                }
-                for request in [
-                    A.joining(required: A.d1),
-                    A.joining(required: A.d2)]
-                {
-                    try assertEqualSQL(db, request, """
-                        SELECT "a".* \
-                        FROM "a" \
-                        JOIN "b" ON ("b"."id" = "a"."bId") \
-                        JOIN "c" ON ("c"."id" = "b"."cId") \
-                        JOIN "d" ON ("d"."cId" = "c"."id")
-                        """)
-                }
-            }
+            try testHasOneWithThreeSteps(
+                db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB,
+                bCondition: "(\"b\".\"id\" = \"a\".\"bId\")",
+                cCondition: "(\"c\".\"id\" = \"b\".\"cId\")",
+                dCondition: "(\"d\".\"cId\" = \"c\".\"id\")")
         }
     }
     

                t.column("bId").references("b")
            }
            
            do {
                try assertEqualSQL(db, A.including(optional: A.c), """
                    SELECT "a".*, "c".* \
                    FROM "a" \
                    LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(required: A.c), """
                    SELECT "a".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(optional: A.c), """
                    SELECT "a".* \
                    FROM "a" \
                    LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(required: A.c), """
                    SELECT "a".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
            }
            do {
                try assertEqualSQL(db, A.including(optional: A.c).including(optional: A.b), """
                    SELECT "a".*, "b".*, "c".* \
                    FROM "a" \
                    LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(optional: A.c).including(required: A.b), """
                    SELECT "a".*, "b".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(optional: A.c).joining(optional: A.b), """
                    SELECT "a".*, "c".* \
                    FROM "a" \
                    LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(optional: A.c).joining(required: A.b), """
                    SELECT "a".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
            }
            do {
                try assertEqualSQL(db, A.including(required: A.c).including(optional: A.b), """
                    SELECT "a".*, "b".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(required: A.c).including(required: A.b), """
                    SELECT "a".*, "b".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(required: A.c).joining(optional: A.b), """
                    SELECT "a".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.including(required: A.c).joining(required: A.b), """
                    SELECT "a".*, "c".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
            }
            do {
                try assertEqualSQL(db, A.joining(optional: A.c).including(optional: A.b), """
                    SELECT "a".*, "b".* \
                    FROM "a" \
                    LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(optional: A.c).including(required: A.b), """
                    SELECT "a".*, "b".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(optional: A.c).joining(optional: A.b), """
                    SELECT "a".* \
                    FROM "a" \
                    LEFT JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(optional: A.c).joining(required: A.b), """
                    SELECT "a".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    LEFT JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
            }
            do {
                try assertEqualSQL(db, A.joining(required: A.c).including(optional: A.b), """
                    SELECT "a".*, "b".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(required: A.c).including(required: A.b), """
                    SELECT "a".*, "b".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(required: A.c).joining(optional: A.b), """
                    SELECT "a".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
                try assertEqualSQL(db, A.joining(required: A.c).joining(required: A.b), """
                    SELECT "a".* \
                    FROM "a" \
                    JOIN "b" ON ("b"."id" = "a"."bId") \
                    JOIN "c" ON ("c"."bId" = "b"."id")
                    """)
            }
        }
    }
    

                t.column("bId").references("b")
            }
            
            try testHasOneWithTwoSteps(
                db, ab: A.b, ac: A.c,
                bCondition: "(\"b\".\"id\" = \"a\".\"bId\")",
                cCondition: "(\"c\".\"id\" = \"b\".\"cId\")")
        }
    }
    
