From 0af8b891409c76e93affa32722feaad6548caebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 11 Feb 2021 20:56:05 +0100 Subject: [PATCH] rel names cant be empty --- yopa/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/yopa/src/lib.rs b/yopa/src/lib.rs index 19c4d81..0d878b0 100644 --- a/yopa/src/lib.rs +++ b/yopa/src/lib.rs @@ -81,8 +81,8 @@ impl Storage { /// Define a relation between two data objects pub fn define_relation(&mut self, mut rel: model::RelationModel) -> Result { - if rel.name.is_empty() { - return Err(StorageError::ConstraintViolation("name must not be empty".into())); + if rel.name.is_empty() || rel.reciprocal_name.is_empty() { + return Err(StorageError::ConstraintViolation("names must not be empty".into())); } if !self.obj_models.contains_key(&rel.object) { @@ -378,6 +378,10 @@ impl Storage { // Updates pub fn update_object(&mut self, model : ObjectModel) -> Result<(), StorageError> { + if model.name.is_empty() { + return Err(StorageError::ConstraintViolation(format!("Model name must not be empty.").into())); + } + if !self.obj_models.contains_key(&model.id) { return Err(StorageError::NotExist(format!("Object model ID {} does not exist.", model.id).into())); } @@ -391,6 +395,10 @@ impl Storage { } pub fn update_relation(&mut self, mut rel : RelationModel) -> Result<(), StorageError> { + if rel.name.is_empty() || rel.reciprocal_name.is_empty() { + return Err(StorageError::ConstraintViolation(format!("Relation names must not be empty.").into())); + } + // Object and Related can't be changed, so we re-fill them from the existing model if let Some(existing) = self.rel_models.get(&rel.id) { rel.object = existing.object;