                 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"."id" = "c"."dId")
-                        """)
-                }
-                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"."id" = "c"."dId")
-                        """)
-                }
-                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"."id" = "c"."dId")
-                        """)
-                }
-                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"."id" = "c"."dId")
-                        """)
-                }
-            }
+            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\".\"id\" = \"c\".\"dId\")")
         }
     }
     

                t.column("dId").references("d")
            }
            
            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"."aId" = "a"."id") \
                        LEFT JOIN "c" ON ("c"."bId" = "b"."id") \
                        LEFT JOIN "d" ON ("d"."id" = "c"."dId")
                        """)
                }
                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"."aId" = "a"."id") \
                        JOIN "c" ON ("c"."bId" = "b"."id") \
                        JOIN "d" ON ("d"."id" = "c"."dId")
                        """)
                }
                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"."aId" = "a"."id") \
                        LEFT JOIN "c" ON ("c"."bId" = "b"."id") \
                        LEFT JOIN "d" ON ("d"."id" = "c"."dId")
                        """)
                }
                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"."aId" = "a"."id") \
                        JOIN "c" ON ("c"."bId" = "b"."id") \
                        JOIN "d" ON ("d"."id" = "c"."dId")
                        """)
                }
            }
        }
    }
    

        struct A: TableRecord {
            static let b = belongsTo(B.self)
            static let c = hasOne(B.c, through: b)
            static let dThroughC = hasOne(C.d, through: c)
            static let dThroughB = hasOne(B.d, through: b)
        }
        struct B: TableRecord {
            static let c = hasOne(C.self)
