rel names cant be empty

master
Ondřej Hruška 4 years ago
parent bf7e9a1871
commit 0af8b89140
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 12
      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<ID, StorageError> {
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;

Loading…
Cancel
Save