imrpove read related fallback to old connector impl
@@ -107,11 +107,19 @@ fn read_related<'a, 'b>(
}
};
+ let relation = query.parent_field.relation();
+
dbg!("RELATION: {}", &query.parent_field.relation().manifestation);
- let mut scalars = if query.parent_field.relation().is_many_to_many() {
+ dbg!("READ RELATED", &parent_result);
+
+ // prisma level join does not work for many 2 many yet
+ // can only work if we have a parent result. This is not the case when we e.g. have nested delete inside an update
+ let use_prisma_level_join = !relation.is_many_to_many() && parent_result.is_some();
+
+ let mut scalars = if !use_prisma_level_join {
tx
.get_related_records(&query.parent_field, &relation_parent_ids, query.args.clone(), &query.selected_fields)
.await?
@@ -152,8 +160,10 @@ fn read_related<'a, 'b>(
.await?
};
+ if use_prisma_level_join {
// Write parent IDs into the retrieved records
if parent_result.is_some() && query.parent_field.is_inlined_on_enclosing_model() {
+ dbg!("The relation is inlined in the parent model");
let parent_identifier = query.parent_field.model().primary_identifier();
let field_names = scalars.field_names.clone();
@@ -194,6 +204,7 @@ fn read_related<'a, 'b>(
scalars.records.extend(additional_records);
} else if parent_result.is_some() && query.parent_field.related_field().is_inlined_on_enclosing_model() {
+ dbg!("The relation is inlined in the child model");
let parent_identifier = query.parent_field.model().primary_identifier();
let field_names = scalars.field_names.clone();
let child_link_fields = query.parent_field.related_field().linking_fields();
@@ -209,8 +220,11 @@ fn read_related<'a, 'b>(
record.parent_id = Some(parent_id);
}
- } else {
+ } else if query.parent_field.relation().is_many_to_many() {
// nothing to do for many to many. parent ids are already present
+ } else {
+ panic!(format!("parent result: {:?}, relation: {:?}", &parent_result, &query.parent_field.relation()));
+ }
}
let model = query.parent_field.related_model();
