project.rs

 1use super::{ProjectId, RoomId, UserId};
 2use sea_orm::entity::prelude::*;
 3
 4#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 5#[sea_orm(table_name = "projects")]
 6pub struct Model {
 7    #[sea_orm(primary_key)]
 8    pub id: ProjectId,
 9    pub room_id: RoomId,
10    pub host_user_id: UserId,
11    pub host_connection_id: u32,
12}
13
14#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
15pub enum Relation {
16    #[sea_orm(
17        belongs_to = "super::user::Entity",
18        from = "Column::HostUserId",
19        to = "super::user::Column::Id"
20    )]
21    HostUser,
22    #[sea_orm(
23        belongs_to = "super::room::Entity",
24        from = "Column::RoomId",
25        to = "super::room::Column::Id"
26    )]
27    Room,
28    #[sea_orm(has_many = "super::worktree::Entity")]
29    Worktrees,
30    #[sea_orm(has_many = "super::project_collaborator::Entity")]
31    Collaborators,
32    #[sea_orm(has_many = "super::language_server::Entity")]
33    LanguageServers,
34}
35
36impl Related<super::user::Entity> for Entity {
37    fn to() -> RelationDef {
38        Relation::HostUser.def()
39    }
40}
41
42impl Related<super::room::Entity> for Entity {
43    fn to() -> RelationDef {
44        Relation::Room.def()
45    }
46}
47
48impl Related<super::worktree::Entity> for Entity {
49    fn to() -> RelationDef {
50        Relation::Worktrees.def()
51    }
52}
53
54impl Related<super::project_collaborator::Entity> for Entity {
55    fn to() -> RelationDef {
56        Relation::Collaborators.def()
57    }
58}
59
60impl Related<super::language_server::Entity> for Entity {
61    fn to() -> RelationDef {
62        Relation::LanguageServers.def()
63    }
64}
65
66impl ActiveModelBehavior for ActiveModel {}