sea-orm-taggable 0.1.0

Tags for any SeaORM entity: attach, detach, sync, tag types, ordering and tag filters
Documentation
//! The `taggables` pivot table: which tag is on which row, and in which position.

use sea_orm::entity::prelude::*;

/// One tag on one tagged row.
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "taggables")]
pub struct Model {
    /// The tag.
    #[sea_orm(primary_key, auto_increment = false)]
    pub tag_id: i64,
    /// The tagged entity's morph type, such as `"post"`.
    #[sea_orm(primary_key, auto_increment = false)]
    pub taggable_type: String,
    /// The tagged row's primary key.
    #[sea_orm(primary_key, auto_increment = false)]
    pub taggable_id: i64,
    /// The tag's position on this row, from 1.
    pub position: i32,
}

/// The pivot's relations.
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    /// The tag; deleting it removes its pivot rows.
    #[sea_orm(
        belongs_to = "super::tag::Entity",
        from = "Column::TagId",
        to = "super::tag::Column::Id",
        on_delete = "Cascade"
    )]
    Tag,
}

impl Related<super::tag::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Tag.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}