billing_customer.rs

 1use crate::db::{BillingCustomerId, UserId};
 2use sea_orm::entity::prelude::*;
 3
 4/// A billing customer.
 5#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "billing_customers")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: BillingCustomerId,
10    pub user_id: UserId,
11    pub stripe_customer_id: String,
12    pub created_at: DateTime,
13}
14
15#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
16pub enum Relation {
17    #[sea_orm(
18        belongs_to = "super::user::Entity",
19        from = "Column::UserId",
20        to = "super::user::Column::Id"
21    )]
22    User,
23    #[sea_orm(has_many = "super::billing_subscription::Entity")]
24    BillingSubscription,
25}
26
27impl Related<super::user::Entity> for Entity {
28    fn to() -> RelationDef {
29        Relation::User.def()
30    }
31}
32
33impl Related<super::billing_subscription::Entity> for Entity {
34    fn to() -> RelationDef {
35        Relation::BillingSubscription.def()
36    }
37}
38
39impl ActiveModelBehavior for ActiveModel {}