-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
Fix IntoActiveValue
for Option
#323
Conversation
@billy1624 thoughts? |
Given the original model #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "fruit")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub cake_id: Option<i32>,
} Some of the possible mappings are...
|
May I ask @acidic9 for help? Since he is the original author of it |
Thanks @billy1624 for the investigation. So there are different possibilities. In a nutshell,
So I think there is a semantic ambiguity, but probably not a bug. |
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "fruit")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub foo: String,
pub bar: Option<i32>,
}
#[derive(DeriveIntoActiveModel)]
pub struct UpdateFruit {
pub name: String,
pub price: f64, // Sets bar to `Set(Some(price))`
}
#[derive(DeriveIntoActiveModel)]
pub struct UpdateFruit {
pub name: String,
pub price: Option<f64>, // Sets bar to `Set(price)`
}
#[derive(DeriveIntoActiveModel)]
pub struct UpdateFruit2 {
pub name: String,
pub price: Option<Option<f64>>, // Sets bar to `Set(Some(price))` or `Set(None`
} I think this is the ended behaviour of the API I had in mind when writing this.. they are not all working correctly? |
Hi, thanks for your concerns. After reading comments, I agree that it is not a bug, it is just an ambiguity. I think the ambiguity originates from the nullability of fields in #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "fruit")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub non_nullable: String,
pub nullable: Option<String>
} The current code is reasonable for
It works fine now .1 and 2 are achieved by There are some possible desired mapping from
The 3rd of the mapping of |
Yes, it appears our type system cannot properly express the idea of Say, we have a |
Oh, there is the So, from a serde_json standpoint, can we actually enforce the schema of Seems not! Because it maps both This thread might be helpful serde-rs/serde#984 There may not be a good derive macro solution to handle this automatically for now. |
f381a89
to
d952a3e
Compare
I will revisit this after |
bc75b4b
to
e7d7962
Compare
Close it for now, we need to look for a better solution |
Have a better solution now? Thanks. @tyt2y3 |
I managed to implement partial updates using a custom simple Option-like type: |
I wish there was a better solution for this |
Related to #322