feature_flag.rs

 1use sea_orm::entity::prelude::*;
 2
 3use crate::db::FlagId;
 4
 5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "feature_flags")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: FlagId,
10    pub flag: String,
11}
12
13#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
14pub enum Relation {
15    #[sea_orm(has_many = "super::user_feature::Entity")]
16    UserFeature,
17}
18
19impl Related<super::user_feature::Entity> for Entity {
20    fn to() -> RelationDef {
21        Relation::UserFeature.def()
22    }
23}
24
25impl ActiveModelBehavior for ActiveModel {}
26
27pub struct FlaggedUsers;
28
29impl Linked for FlaggedUsers {
30    type FromEntity = Entity;
31
32    type ToEntity = super::user::Entity;
33
34    fn link(&self) -> Vec<RelationDef> {
35        vec![
36            super::user_feature::Relation::Flag.def().rev(),
37            super::user_feature::Relation::User.def(),
38        ]
39    }
40}