sea-orm
sea-orm copied to clipboard
Trait "Serialize" is not implemented for generated entity, even when I included it in the file.
Description
Generated entity files via sea orm cli. Here's what it looks like:
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use rocket::serde::{Serialize, Deserialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(crate = "rocket::serde")]
#[sea_orm(table_name = "user")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub name: String,
#[sea_orm(unique)]
pub telegram: String,
#[sea_orm(unique)]
pub email: String,
pub password: String,
pub city: String,
pub country: String,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, Serialize, Deserialize)]
pub enum Relation {
#[sea_orm(has_many = "super::boost::Entity")]
Boost,
}
impl Related<super::boost::Entity> for Entity {
fn to() -> RelationDef {
Relation::Boost.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
I'm trying to use it in a different lib in the same project:
#[derive(Serialize)]
pub enum ResponseBody {
Message(String),
User(User),
Users(Vec<User>)
}
But it throws:
error[E0277]: the trait bound `domain::entities::prelude::User: Serialize` is not satisfied
--> shared/src/response_models.rs:5:10
|
5 | #[derive(Serialize)]
| ^^^^^^^^^ the trait `Serialize` is not implemented for `domain::entities::prelude::User`
...
10 | User(User),
| ---- required by a bound introduced by this call
|
= note: for local types consider adding `#[derive(serde::Serialize)]` to your `domain::entities::prelude::User` type
= note: for types from other crates check whether the crate offers a `serde` feature flag
= help: the following other types implement trait `Serialize`:
&'a T
&'a UncasedStr
&'a mut T
()
(T,)
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
and 238 others
note: required by a bound in `serialize_newtype_variant`
--> .../.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.215/src/ser/mod.rs:943:21
|
935 | fn serialize_newtype_variant<T>(
| ------------------------- required by a bound in this associated function
...
943 | T: ?Sized + Serialize;
| ^^^^^^^^^ required by this bound in `Serializer::serialize_newtype_variant`
= note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)
I genuinely think it has something to do with the DeriveEntityModel trait, and how exactly it converts Model to Entity under the hood.
I genuinely hope this is coherent enough. I've had to type this 3 times already cos I keep accidentally leaving this page, and I'm sleep deprived atp.
Steps to Reproduce
- Use the cli to generate entities from migration files in one lib.
- create a different lib, and attempt to use ```Serialize trait``` on an enum containing the entity exported by prelude.rs. it should throw same error.
Expected Behavior
for it to just work?Actual Behavior
Threw errors.
Reproduces How Often
I believe so.
Workarounds
Changed pub use super::user::Entity as User; to pub use super::user::Model as User; and it seemingly compiles fine.
Reproducible Example
Versions
├── sea-orm v1.1.2 │ ├── sea-orm-macros v1.1.2 (proc-macro) │ │ ├── sea-bae v0.2.1 (proc-macro) │ ├── sea-query v0.32.1 │ ├── sea-query-binder v0.7.0 │ │ ├── sea-query v0.32.1 (*)
Running Linux.