Make sure category is linked when setting it

This commit is contained in:
Matthias Beyer 2018-04-26 11:20:09 +02:00
parent 0bacfb0a88
commit f321aa82a1

View file

@ -72,12 +72,15 @@ impl EntryCategory for Entry {
/// ///
/// This function should be used by default over EntryCategory::set_category()! /// This function should be used by default over EntryCategory::set_category()!
fn set_category_checked(&mut self, register: &CategoryRegister, s: Category) -> Result<()> { fn set_category_checked(&mut self, register: &CategoryRegister, s: Category) -> Result<()> {
register.category_exists(&s.0) let c_str = s.clone().into();
.and_then(|bl| if bl { let mut category = register
self.set_category(s) .get_category_by_name(&c_str)?
} else { .ok_or_else(|| CE::from_kind(CEK::CategoryDoesNotExist))?;
Err(CE::from_kind(CEK::CategoryDoesNotExist))
}) let _ = self.set_category(s)?;
let _ = self.add_internal_link(&mut category)?;
Ok(())
} }
fn get_category(&self) -> Result<Option<Category>> { fn get_category(&self) -> Result<Option<Category>> {