Skip to main content

morph_target

Macro morph_target 

Source
macro_rules! morph_target {
    (
        $(#[$meta:meta])*
        $vis:vis enum $name:ident {
            $($variant:ident($entity:path)),+ $(,)?
        }
    ) => { ... };
}
Expand description

Declares the possible owners of a polymorphic child as an enum, and implements MorphTarget for it.

sea_orm_relations_kit::morph_target! {
    /// Whatever a comment can be left on.
    #[derive(Clone, Debug)]
    pub enum Commentable {
        Post(posts::Entity),
        Video(videos::Entity),
    }
}

let owner = Commentable::Post(posts::Model { id: 1 });
assert_eq!(owner.morph_type(), "post");