channel.rs

 1use crate::db::ChannelId;
 2use sea_orm::entity::prelude::*;
 3
 4#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
 5#[sea_orm(table_name = "channels")]
 6pub struct Model {
 7    #[sea_orm(primary_key)]
 8    pub id: ChannelId,
 9    pub name: String,
10}
11
12impl ActiveModelBehavior for ActiveModel {}
13
14#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
15pub enum Relation {
16    #[sea_orm(has_one = "super::room::Entity")]
17    Room,
18    #[sea_orm(has_one = "super::buffer::Entity")]
19    Buffer,
20    #[sea_orm(has_many = "super::channel_member::Entity")]
21    Member,
22    #[sea_orm(has_many = "super::channel_buffer_collaborator::Entity")]
23    BufferCollaborators,
24}
25
26impl Related<super::channel_member::Entity> for Entity {
27    fn to() -> RelationDef {
28        Relation::Member.def()
29    }
30}
31
32impl Related<super::room::Entity> for Entity {
33    fn to() -> RelationDef {
34        Relation::Room.def()
35    }
36}
37
38impl Related<super::buffer::Entity> for Entity {
39    fn to() -> RelationDef {
40        Relation::Buffer.def()
41    }
42}
43
44impl Related<super::channel_buffer_collaborator::Entity> for Entity {
45    fn to() -> RelationDef {
46        Relation::BufferCollaborators.def()
47    }
48}