Skip to content
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

Implement IntoActiveValue for time types. #1041

Merged
merged 6 commits into from
Sep 18, 2022

Conversation

jimmycuadra
Copy link
Contributor

I tried to implement a custom active model, and one of the columns was Option<TimeDateTimeWithTimeZone>. I got a compiler error:

error[E0277]: the trait bound `std::option::Option<sea_orm::prelude::TimeDateTimeWithTimeZone>: IntoActiveValue<_>` is not satisfied

Looking into the source code, it seemed a simple oversight that this trait was implemented for the chrono types but not the time types, and it was easy enough to fix since there's already a macro to implement it for new types.

I also noticed that the time types are not accounted for in src/query/json.rs while the chrono types are, which I assume is also an oversight. However, I don't have a need for that at this point and the fix for that seemed less trivial, so I'm just bringing it to your attention.

Thanks for SeaORM!

I tried to implement a [custom active
model](https://www.sea-ql.org/SeaORM/docs/advanced-query/custom-active-model/),
and one of the columns was `Option<TimeDateTimeWithTimeZone>`. I got a
compiler error:

```
error[E0277]: the trait bound `std::option::Option<sea_orm::prelude::TimeDateTimeWithTimeZone>: IntoActiveValue<_>` is not satisfied
```

Looking into the source code, it seemed a simple oversight that this
trait was implemented for the `chrono` types but not the `time` types,
and it was easy enough to fix since there's already a macro to implement
it for new types.

I also noticed that the `time` types are not accounted for in
`src/query/json.rs` while the `chrono` types are, which I assume is also
an oversight. However, I don't have a need for that at this point and
the fix for that seemed less trivial, so I'm just bringing it to your
attention.

Thanks for SeaORM!
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jimmycuadra, thanks for the report and the PR!!

Yes, this is an oversight. And I want to prevent this from happening again by adding test cases and leave a note for all other developers. Please check and merge jimmycuadra#1.

Also, I will address the serialization of time types as serde_json::Value at #1042.

@jimmycuadra
Copy link
Contributor Author

Thank you for the fast response! I've merged your PR into my branch.

@tyt2y3 tyt2y3 merged commit 4e51b88 into SeaQL:master Sep 18, 2022
@tyt2y3
Copy link
Member

tyt2y3 commented Sep 18, 2022

Thank you

@jimmycuadra jimmycuadra deleted the with-time-into-active-model branch September 19, 2022 00:38
tyt2y3 added a commit that referenced this pull request Sep 19, 2022
Implement `IntoActiveValue` for `time` types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants