Test optional 1:1 relations
@@ -350,3 +350,23 @@ fn implicit_fk_name_definition_with_mapped_models_and_fields_other_order() {
.assert_relation_referenced_fields(&["user_id"])
.assert_relation_fk_name(Some("PostMap_user_id_map_on_post_fkey".to_string()));
}
+
+#[test]
+fn one_to_one_optional() {
+ let dml = r#"
+ model A {
+ id Int @id
+ b B?
+ }
+
+ model B {
+ id Int @id
+ a_id Int?
+ a A? @relation(fields: [a_id], references: [id])
+ }
+ "#;
+
+ let schema = parse(&dml);
+ schema.assert_has_model("A").assert_has_relation_field("b");
+ schema.assert_has_model("B").assert_has_relation_field("a");
+}
