You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my models I have the created_at/updated_at columns defined as TimestampWithTimeZone.
When I retrieve the models, the TimestampWithTimeZone columns are returned as arrays with a strange format, like \"created_at\":[2024,75,16,24,39,144518000,0,0,0]} but I was expecting an ISO8601, something more like \"created_at\":\"+002024-03-15T16:26:38.178125000Z\" that my frontend can consume directly.
Reproduces How Often
Always reproducible.
Workarounds
My work around currently is to generate my entities with sea-orm-cli generate entity -o "entity/src/entities" --with-serde both --date-time-crate time, then to manually edit the models everywhere I use a TimestampWithTimeZone and add this serde attribute: #[serde(with = "time::serde::iso8601")]. However this approach does not scale.
Is there a way to have seaorm automatically add the serde attribute for the TimestampWithTimeZone fields?
Reproducible Example
entity/src/entities/submission.rs:
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14usesuper::sea_orm_active_enums::ApprovalStatus;use sea_orm::entity::prelude::*;use serde::{Deserialize,Serialize};#[derive(Clone,Debug,PartialEq,DeriveEntityModel,Eq,Serialize,Deserialize)]#[sea_orm(table_name = "submission")]pubstructModel{#[sea_orm(primary_key)]pubid:i32,pubfirst_name:String,publast_name:String,pubtitle:Option<String>,puborganization:Option<String>,pubemail:String,pubcountry:String,pubcity:String,pubregion:Option<String>,pubfips_code:String,pubconsent:bool,pubcreated_at:TimeDateTimeWithTimeZone,}#[derive(Copy,Clone,Debug,EnumIter,DeriveRelation)]pubenumRelation{}implActiveModelBehaviorforActiveModel{}#[cfg(test)]mod tests {usesuper::*;#[test]fntest_date_ser(){let m = submission::Model{id:1,first_name:String::from("first_name"),last_name:String::from("last_name"),title:Some(String::from("title")),organization:Some(String::from("organization")),email:String::from("email"),country:String::from("country"),city:String::from("city"),region:Some(String::from("region")),fips_code:String::from("fips_code"),consent:true,created_at:TimeDateTimeWithTimeZone::now_utc(),};let d = serde_json::to_string(&m).unwrap();dbg!(d);}}
Description & Expected Behavior
In my models I have the created_at/updated_at columns defined as
TimestampWithTimeZone
.When I retrieve the models, the
TimestampWithTimeZone
columns are returned as arrays with a strange format, like\"created_at\":[2024,75,16,24,39,144518000,0,0,0]}
but I was expecting an ISO8601, something more like\"created_at\":\"+002024-03-15T16:26:38.178125000Z\"
that my frontend can consume directly.Reproduces How Often
Always reproducible.
Workarounds
My work around currently is to generate my entities with
sea-orm-cli generate entity -o "entity/src/entities" --with-serde both --date-time-crate time
, then to manually edit the models everywhere I use aTimestampWithTimeZone
and add this serde attribute:#[serde(with = "time::serde::iso8601")]
. However this approach does not scale.Is there a way to have seaorm automatically add the serde attribute for the TimestampWithTimeZone fields?
Reproducible Example
entity/src/entities/submission.rs
:The JSON output is:
Versions
I am using seaorm 0.12.14 with the time library.
The text was updated successfully, but these errors were encountered: