Use DeriveEntityModel without having a Relation enum #644
Replies: 4 comments
-
Hey @LasseRosenow, welcome! Take the entity below as an example, you're saying that you want to get rid of the empty use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "posts")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
pub title: String,
#[sea_orm(column_type = "Text")]
pub text: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {} |
Beta Was this translation helpful? Give feedback.
-
@billy1624 yes. As far as I understand, I don't really need the So I didn't like to have things at multiple places so I got rid of all the stuff inside the Relation enum and moved it inside the related traits. So long answer short: yes I would like not to have those empty structures that I don't use, but if there are technical reasons as to why they need to exist, that would okay too of course :) |
Beta Was this translation helpful? Give feedback.
-
This all of course would not be necessary if the Relation enum derive macro would work as documented. See this screenshot from the documentation says that the whole first code block could be replaced by the one at the bottom which is using the macro, but I could not reproduce this. When I only used the lower one with the macro, I still had to write the Because if I could specify all my relations just with the Relation enum using macros, that would be cool as well and a good alternative to getting rid of the enum and doing everything with the |
Beta Was this translation helpful? Give feedback.
-
The macro annotation only handles the impl of the |
Beta Was this translation helpful? Give feedback.
-
Summary
Right now, when I use the
DeriveEntityModel
Derive Macro
, I need to have aenum Relation
, which derivesDeriveRelation
.Otherwise I get the error:
cannot find type
Relationin this scope
.Motivation
The reason why I would like to use the
DeriveEntityModel
macro without having the Relation enum is because I don't use the Relation enum.I like to define my relations like this:
So there really is no need and it works... Right now I just have an empty Relation enum and that just feels a bit useless and adds unnecessary clutter.
Beta Was this translation helpful? Give feedback.
All reactions