Skip to content

The derive macro DeriveRelation does not generate Related trait for entity. Is this normal ? #752

Answered by billy1624
leo91000 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @leo91000, welcome and thanks for asking. DeriveRelation does not generate Related implementation for you. Take this for an example, it only implements RelationTrait for you.

The DeriveRelation macro is a simple wrapper to impl the RelationTrait.

#[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

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@LasseRosenow
Comment options

Answer selected by billy1624
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants