-
I was following the doc to create a one to many relationship. When I use manual trait implementation, it works fine. However, when I'm using the macro way with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @leo91000, welcome and thanks for asking. The #[derive(DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::fruit::Entity")]
Fruit,
} expands into impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Fruit => Entity::has_many(super::fruit::Entity).into(),
}
}
} https://www.sea-ql.org/SeaORM/docs/generate-entity/entity-structure#relation |
Beta Was this translation helpful? Give feedback.
-
Perhaps we can have a proc macro and a DSL, although I don't like DSLs too much related!(cake::Entity -> cake_filling::Relation::Cake.def().rev() -> cake_filling::Relation::Filling.def() -> fruit::Entity); in place of impl Related<super::filling::Entity> for Entity {
fn to() -> RelationDef {
super::cake_filling::Relation::Filling.def()
}
fn via() -> Option<RelationDef> {
Some(super::cake_filling::Relation::Cake.def().rev())
}
} Does that actually make it more readable / understandable / easier to write? |
Beta Was this translation helpful? Give feedback.
Hey @leo91000, welcome and thanks for asking.
DeriveRelation
does not generateRelated
implementation for you. Take this for an example, it only implementsRelationTrait
for you.The
DeriveRelation
macro is a simple wrapper to impl theRelationTrait
.expands into
https://www.sea-ql.org/SeaORM/docs/generate-entity/entity-structure#relation