diff --git a/yopa-web/resources/templates/index.html.tera b/yopa-web/resources/templates/index.html.tera
index 3a3e3b1..5205794 100644
--- a/yopa-web/resources/templates/index.html.tera
+++ b/yopa-web/resources/templates/index.html.tera
@@ -39,13 +39,12 @@
{% endif %}
-
{% if model.relations %}
Relations:
{% for rel in model.relations %}
-
- "{{rel.model.name}}", pointing to: {{rel.related_name}} (reciprocal as "{{rel.model.reciprocal_name}}")
+ "{{rel.model.name}}" -> {{rel.related_name}} (reciprocally as "{{rel.model.reciprocal_name}}")
{%- if rel.model.optional %}, OPTIONAL{% endif %}
{%- if rel.model.multiple %}, MULTIPLE{% endif %}
@@ -68,6 +67,17 @@
{% endfor %}
{% endif %}
+
+ {% if model.reciprocal_relations %}
+ Incoming relations:
+
+ {% for rel in model.reciprocal_relations %}
+ -
+ "{{rel.model.reciprocal_name}}" <- {{rel.related_name}} (reciprocally as "{{rel.model.name}}")
+
+ {% endfor %}
+
+ {% endif %}
{% endfor %}
diff --git a/yopa-web/src/routes.rs b/yopa-web/src/routes.rs
index 3b165fb..a527a83 100644
--- a/yopa-web/src/routes.rs
+++ b/yopa-web/src/routes.rs
@@ -17,6 +17,7 @@ struct ObjectModelDisplay<'a> {
name : &'a str,
properties: Vec<&'a PropertyModel>,
relations: Vec>,
+ reciprocal_relations: Vec>,
}
#[derive(Serialize, Debug)]
@@ -73,14 +74,13 @@ pub(crate) async fn index(session : Session, store : crate::YopaStoreWrapper) ->
let mut model_props = rg.get_grouped_prop_models();
let mut model_relations = rg.get_grouped_relation_models();
+ let mut model_rec_relations = rg.get_grouped_reciprocal_relation_models();
let mut models = vec![];
for om in models_iter {
- let mut oprops = model_props.remove(&om.id).unwrap_or_default();
let mut relations = model_relations.remove(&om.id).unwrap_or_default();
-
- let rel_displays = relations.into_iter().map(|rm| {
- let mut rprops = model_props.remove(&rm.id).unwrap_or_default();
+ let mut relations = relations.into_iter().map(|rm| {
+ let mut rprops = model_props.get(&rm.id).cloned().unwrap_or_default();
rprops.sort_by_key(|m| &m.name);
RelationModelDisplay {
@@ -88,16 +88,32 @@ pub(crate) async fn index(session : Session, store : crate::YopaStoreWrapper) ->
related_name: rg.get_model_name(rm.related),
properties: rprops
}
+ }).collect::>();
+ relations.sort_by_key(|d| &d.model.name);
+
+ // Relations coming INTO this model
+ let mut reciprocal_relations = model_rec_relations.remove(&om.id).unwrap_or_default();
+ let mut reciprocal_relations = reciprocal_relations.into_iter().map(|rm| {
+ let mut rprops = model_props.get(&rm.id).cloned().unwrap_or_default();
+ rprops.sort_by_key(|m| &m.name);
+ RelationModelDisplay {
+ model: rm,
+ related_name: rg.get_model_name(rm.object),
+ properties: rprops
+ }
}).collect::>();
+ reciprocal_relations.sort_by_key(|d| &d.model.reciprocal_name);
- oprops.sort_by_key(|m| &m.name);
+ let mut properties = model_props.remove(&om.id).unwrap_or_default();
+ properties.sort_by_key(|m| &m.name);
models.push(ObjectModelDisplay {
id: om.id,
name: &om.name,
- properties: oprops,
- relations: rel_displays,
+ properties,
+ relations,
+ reciprocal_relations
})
}
diff --git a/yopa/src/lib.rs b/yopa/src/lib.rs
index 821d484..7523a17 100644
--- a/yopa/src/lib.rs
+++ b/yopa/src/lib.rs
@@ -370,4 +370,9 @@ impl Storage {
self.rel_models.values()
.into_group_map_by(|model| model.object)
}
+
+ pub fn get_grouped_reciprocal_relation_models(&self) -> HashMap> {
+ self.rel_models.values()
+ .into_group_map_by(|model| model.related)
+ }
}