Skip to content

Commit 4f89d1b

Browse files
committed
Changelog
1 parent e597177 commit 4f89d1b

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

changelog/2.0.0-rc.35.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,98 @@ Nested transactions correctly fall back to `SAVEPOINT` regardless of the mode.
2121

2222
**Extend `DeriveIntoActiveModel`** (#2961)
2323

24-
`DeriveIntoActiveModel` now supports `set`/`fill`, `default`, `ignore`, and `exhaustive` attributes for more control when converting "form" structs into ActiveModels:
24+
`DeriveIntoActiveModel` now supports `set`/`fill`, `default`, `ignore`, `skip`, `exhaustive`, and custom `active_model` path attributes for fine-grained control when converting "form" or "input" structs into ActiveModels.
25+
26+
**`set` / `fill`** — always set fields not present on the struct:
27+
28+
```rust
29+
#[derive(DeriveIntoActiveModel)]
30+
#[sea_orm(active_model = "fruit::ActiveModel", fill(cake_id = "None"))]
31+
struct NewFruit {
32+
name: String,
33+
// cake_id is not on the struct, but will always be Set(None)
34+
}
35+
36+
NewFruit { name: "Apple".into() }.into_active_model()
37+
// => ActiveModel { id: NotSet, name: Set("Apple"), cake_id: Set(None) }
38+
```
39+
40+
Multiple `set` entries can be combined or split across attributes:
41+
42+
```rust
43+
#[derive(DeriveIntoActiveModel)]
44+
#[sea_orm(
45+
active_model = "fruit::ActiveModel",
46+
set(name = "String::from(\"cherry\")", cake_id = "None")
47+
)]
48+
struct IdOnlyFruit {
49+
id: i32,
50+
}
51+
52+
IdOnlyFruit { id: 1 }.into_active_model()
53+
// => ActiveModel { id: Set(1), name: Set("cherry"), cake_id: Set(None) }
54+
```
55+
56+
**`default`** — fallback value when an `Option<T>` field is `None`:
57+
58+
```rust
59+
#[derive(DeriveIntoActiveModel)]
60+
#[sea_orm(active_model = "fruit::ActiveModel")]
61+
struct NewFruit {
62+
#[sea_orm(default = "String::from(\"Unnamed\")")]
63+
name: Option<String>,
64+
}
65+
66+
NewFruit { name: Some("Apple".into()) }.into_active_model()
67+
// => ActiveModel { id: NotSet, name: Set("Apple"), cake_id: NotSet }
68+
69+
NewFruit { name: None }.into_active_model()
70+
// => ActiveModel { id: NotSet, name: Set("Unnamed"), cake_id: NotSet }
71+
```
72+
73+
Bare `#[sea_orm(default)]` (without a value) uses `Default::default()` as the fallback. This also works with custom enum types that implement `Into<Option<T>>`.
74+
75+
**`ignore` / `skip`** — exclude struct fields from the ActiveModel:
2576

2677
```rust
2778
#[derive(DeriveIntoActiveModel)]
28-
#[sea_orm(active_model = "fruit::ActiveModel", set(cake_id = "None"))]
79+
#[sea_orm(active_model = "fruit::ActiveModel")]
2980
struct NewFruit {
3081
name: String,
82+
cake_id: i32,
83+
#[sea_orm(ignore)]
84+
_extra: String, // not mapped to ActiveModel
85+
}
86+
```
87+
88+
**`exhaustive`** — require all ActiveModel fields to be either on the struct or in `set(...)`:
89+
90+
```rust
91+
#[derive(DeriveIntoActiveModel)]
92+
#[sea_orm(active_model = "fruit::ActiveModel", exhaustive, set(cake_id = "None"))]
93+
struct FullFruit {
94+
id: i32,
95+
name: String,
96+
// cake_id is covered by set(...), so all fields are accounted for
97+
}
98+
```
99+
100+
**Combining everything**`set` + `default` + `ignore` + `exhaustive`:
101+
102+
```rust
103+
#[derive(DeriveIntoActiveModel)]
104+
#[sea_orm(active_model = "fruit::ActiveModel", exhaustive, set(cake_id = "None"))]
105+
struct NewFruit {
106+
id: i32,
31107
#[sea_orm(default = "String::from(\"Unnamed\")")]
32-
optional_label: Option<String>,
108+
name: Option<String>,
33109
}
110+
111+
NewFruit { id: 1, name: Some("Apple".into()) }.into_active_model()
112+
// => ActiveModel { id: Set(1), name: Set("Apple"), cake_id: Set(None) }
113+
114+
NewFruit { id: 2, name: None }.into_active_model()
115+
// => ActiveModel { id: Set(2), name: Set("Unnamed"), cake_id: Set(None) }
34116
```
35117

36118
**`IntoSimpleExpr` for `FunctionCall`** (#2822)

0 commit comments

Comments
 (0)