-
-
Notifications
You must be signed in to change notification settings - Fork 539
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
Blanket IntoActiveValue implementations so custom db types are supported #833
Conversation
I agree that we should support |
see the discussion here: #323 |
Ah thank you for the context |
Sorry but I need more information on exactly what you are trying to do that does not compile, and how this change fixes it now. It'd be great if you can add a test case somewhere under tests/features. It will also ensure that it will be well maintained in the future |
Sorry i linked the wrong issue, i changed it in my previous comment |
Ah I see, well it's a complicated topic - type system! Definitely needed some test cases then |
There doesn't seem to be any current test cases around For more context, this currently doesn't work: #[derive(Debug, Clone, DeriveIntoActiveModel)]
pub struct User {
pub name: Option<String>,
pub email: Option<Option<String>>,
pub language: Option<Option<Language>>,
} because of the error:
where #[derive(Hash, Eq, Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "language")]
pub enum Language {
#[sea_orm(string_value = "en_US")]
EnUs,
#[sea_orm(string_value = "fr_FR")]
FrFr,
#[sea_orm(string_value = "nl_NL")]
NlNl,
...
} If really necessary i can still add some tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @wdcocq, sorry for the delay! Thank you so much for the contributions!!
Yes, please! Adding more test cases would be appreciated :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tyt2y3, this PR shouldn't change behaviour of the IntoActiveValiue
as it's just refactoring a concrete trait implementation to blanket implementation. However, I'll flag this PR as breaking changes. Because any downstream implemented IntoActiveValue
for Option<V>
and Option<Option<V>>
will be forbidden.
Is this breaking though, as you already can't do this anyway? Unless I'm missing something :)
I already added a test that should test whether it compiles with custom types (and some primitives). Not sure what else to add for this PR that's not testing the functionality of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
PR Info
Currently it doesn't seem possible to use
DeriveIntoActiveModel
with a field withOption<Option<CustomDbType>>
orOption<CustomDbType>
because theIntoActiveValue<Option<CustomDbType>>
trait is missing.Because of the orphan rule you can't implement
IntoActiveValue<Option<CustomDbType>> for Option<CustomDbType>
. You can for justCustomDbType
of course.Changes
By changing the
Option<T>
andOption<Option<T>>
from being implemented by theimpl_into_active_value
macro, to blanket implementations this will work for every type that implementsIntoActiveValue<T>
Will make it possible to use
DeriveIntoActiveModel
on structs with aOption<Option<CustomDbType>>
field