diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index ceb4f726e..0fd54b713 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -548,6 +548,12 @@ pub trait ActiveModelTrait: Clone + Debug { Ok(am) } + + /// Returns `true` if any columns were changed. + fn is_changed(&self) -> bool { + ::Column::iter() + .any(|col| self.get(col).is_set() && !self.get(col).is_unchanged()) + } } /// A Trait for overriding the ActiveModel behavior @@ -1088,4 +1094,13 @@ mod tests { Ok(()) } + + #[test] + fn test_active_model_is_changed() { + let mut fruit: fruit::ActiveModel = Default::default(); + assert!(!fruit.is_changed()); + + fruit.set(fruit::Column::Name, "apple".into()); + assert!(fruit.is_changed()); + } }