dfix the bufg]

master
Ondřej Hruška 4 years ago
parent bc8b04f331
commit 58c44afa30
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      yopa-web/src/routes/models/property.rs
  2. 13
      yopa/src/lib.rs

@ -29,7 +29,7 @@ pub(crate) async fn create_form(
context.insert("old", &PropertyModelCreateForm { context.insert("old", &PropertyModelCreateForm {
object: Default::default(), object: Default::default(),
name: "".to_string(), name: "".to_string(),
optional: false, optional: true,
multiple: false, multiple: false,
data_type: DataType::String, data_type: DataType::String,
default: "".to_string() default: "".to_string()

@ -507,11 +507,15 @@ impl Storage {
let mut relations_to_insert = vec![]; let mut relations_to_insert = vec![];
let mut relations_to_delete = vec![]; let mut relations_to_delete = vec![];
let existing_relations_by_id = self.relations.values() let mut existing_relations_by_id = self.relations.values()
.filter(|v| v.object == updated_object_id) .filter(|v| v.object == updated_object_id)
.into_group_map_by(|v| v.model); .into_group_map_by(|v| v.model);
for (relation_model_id, relation_model) in self.rel_models.iter().filter(|(_id, r)| r.object == updated_object_model_id) { let rel_models_by_id = self.rel_models.iter().filter(|(_id, r)| r.object == updated_object_model_id);
for (relation_model_id, relation_model) in rel_models_by_id {
let mut updated_ids = vec![];
if let Some(instances) = relations_by_model.remove(relation_model_id) { if let Some(instances) = relations_by_model.remove(relation_model_id) {
if instances.len() > 1 && !relation_model.multiple { if instances.len() > 1 && !relation_model.multiple {
return Err(StorageError::ConstraintViolation(format!("{} of {} cannot be set multiply", relation_model, obj_model).into())); return Err(StorageError::ConstraintViolation(format!("{} of {} cannot be set multiply", relation_model, obj_model).into()));
@ -541,12 +545,17 @@ impl Storage {
model: rel_instance.model, model: rel_instance.model,
related: rel_instance.related, related: rel_instance.related,
}); });
updated_ids.push(relation_id);
} }
} else { } else {
if !relation_model.optional { if !relation_model.optional {
return Err(StorageError::ConstraintViolation(format!("{} is required for {}", relation_model, obj_model).into())); return Err(StorageError::ConstraintViolation(format!("{} is required for {}", relation_model, obj_model).into()));
} }
} }
relations_to_delete.extend(existing_relations_by_id.remove(&relation_model_id).unwrap_or_default().into_iter()
.filter(|rel| !updated_ids.contains(&rel.id)).map(|rel| rel.id));
} }
let obj_mut = self.objects.get_mut(&updated_object_id).unwrap(); let obj_mut = self.objects.get_mut(&updated_object_id).unwrap();

Loading…
Cancel
Save