Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_changed to ActiveModelTrait #683

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/entity/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ pub trait ActiveModelTrait: Clone + Debug {

Ok(am)
}

/// Returns `true` if any columns were changed.
fn is_changed(&self) -> bool {
<Self::Entity as EntityTrait>::Column::iter()
.any(|col| self.get(col).is_set() && !self.get(col).is_unchanged())
}
}

/// A Trait for overriding the ActiveModel behavior
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//!
//!
billy1624 marked this conversation as resolved.
Show resolved Hide resolved
//! For more projects, see [Built with SeaORM](https://github.com/SeaQL/sea-orm/blob/master/COMMUNITY.md#built-with-seaorm).
//!
//! ## License
Expand Down