use crate::db::{ChannelId, MessageId, UserId}; use sea_orm::entity::prelude::*; use time::PrimitiveDateTime; #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] #[sea_orm(table_name = "channel_messages")] pub struct Model { #[sea_orm(primary_key)] pub id: MessageId, pub channel_id: ChannelId, pub sender_id: UserId, pub body: String, pub sent_at: PrimitiveDateTime, pub nonce: Uuid, } impl ActiveModelBehavior for ActiveModel {} #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { #[sea_orm( belongs_to = "super::channel::Entity", from = "Column::ChannelId", to = "super::channel::Column::Id" )] Channel, #[sea_orm( belongs_to = "super::user::Entity", from = "Column::SenderId", to = "super::user::Column::Id" )] Sender, } impl Related for Entity { fn to() -> RelationDef { Relation::Channel.def() } } impl Related for Entity { fn to() -> RelationDef { Relation::Sender.def() } }