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()); + } } diff --git a/src/lib.rs b/src/lib.rs index 1cc42f3a5..0668c7e62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -263,7 +263,7 @@ //! ## Who's using SeaORM? //! //! SeaORM is the foundation of [StarfishQL](https://github.com/SeaQL/starfish-ql), an experimental graph database and query engine. -//! +//! //! For more projects, see [Built with SeaORM](https://github.com/SeaQL/sea-orm/blob/master/COMMUNITY.md#built-with-seaorm). //! //! ## License