Skip to content
Open
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
20 changes: 20 additions & 0 deletions SeaORM/docs/05-basic-crud/03-active-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,23 @@ assert_eq!(
Err(DbErr::AttrNotSet(String::from("name")))
);
```

This will fail if any of the fields of the ActiveModel are `NotSet`.
If you wish to automatically fill remaining fields with their `Default::default()` values (or fallback to `NotSet` if they don't have one), you can use the
[`ActiveModelTrait::default_values()`](https://docs.rs/sea-orm/*/sea_orm/entity/trait.ActiveModelTrait.html#tymethod.default_values) method.
This can be useful for quickly creating mock models for testing purposes.
```rust
assert_eq!(
ActiveModel {
id: Set(2),
..ActiveModel::default_values()
}
.try_into_model()
.unwrap(),
Model {
id: 2,
name: String::default(), // empty string,
cake_id: Option::default(), // `None`
}
);
```