Skip to content

Commit

Permalink
Rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jan 11, 2023
1 parent 88bd12e commit a7ec835
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions sea-orm-macros/src/derives/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ fn derive_active_model(all_fields: IntoIter<Field>) -> syn::Result<TokenStream>
}
}

fn set_dirty(&mut self, c: <Self::Entity as EntityTrait>::Column) {
fn reset(&mut self, c: <Self::Entity as EntityTrait>::Column) {
match c {
#(<Self::Entity as EntityTrait>::Column::#name => self.#field.set_dirty(),)*
#(<Self::Entity as EntityTrait>::Column::#name => self.#field.reset(),)*
_ => panic!("This ActiveModel does not have this field"),
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/entity/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ pub trait ActiveModelTrait: Clone + Debug {
/// The default implementation of the ActiveModel
fn default() -> Self;

/// Set fields of value [ActiveValue::Unchanged] as [ActiveValue::Set]
fn set_dirty(&mut self, c: <Self::Entity as EntityTrait>::Column);
/// Reset the value from [ActiveValue::Unchanged] to [ActiveValue::Set]
fn reset(&mut self, c: <Self::Entity as EntityTrait>::Column);

/// Set all fields of value [ActiveValue::Unchanged] as [ActiveValue::Set]
fn set_all_dirty(mut self) -> Self {
/// Reset all values from [ActiveValue::Unchanged] to [ActiveValue::Set]
fn reset_all(mut self) -> Self {
for col in <Self::Entity as EntityTrait>::Column::iter() {
self.set_dirty(col);
self.reset(col);
}
self
}
Expand Down Expand Up @@ -832,7 +832,7 @@ where
}

/// Convert [ActiveValue::Unchanged] into [ActiveValue::Set]
pub fn set_dirty(&mut self) {
pub fn reset(&mut self) {
*self = match self.take() {
Some(value) => ActiveValue::Set(value),
None => ActiveValue::NotSet,
Expand Down Expand Up @@ -1293,7 +1293,7 @@ mod tests {
}

#[test]
fn test_set_dirty_1() {
fn test_reset_1() {
assert_eq!(
fruit::Model {
id: 1,
Expand All @@ -1315,7 +1315,7 @@ mod tests {
cake_id: None,
}
.into_active_model()
.set_all_dirty(),
.reset_all(),
fruit::ActiveModel {
id: Set(1),
name: Set("Apple".into()),
Expand Down Expand Up @@ -1344,7 +1344,7 @@ mod tests {
cake_id: Some(2),
}
.into_active_model()
.set_all_dirty(),
.reset_all(),
fruit::ActiveModel {
id: Set(1),
name: Set("Apple".into()),
Expand All @@ -1354,7 +1354,7 @@ mod tests {
}

#[smol_potat::test]
async fn test_set_dirty_2() -> Result<(), DbErr> {
async fn test_reset_2() -> Result<(), DbErr> {
use crate::*;

let db = MockDatabase::new(DbBackend::Postgres)
Expand Down Expand Up @@ -1397,7 +1397,7 @@ mod tests {
cake_id: None,
}
.into_active_model()
.set_all_dirty()
.reset_all()
.update(&db)
.await?;

Expand Down

0 comments on commit a7ec835

Please sign in to comment.