server: Add an entity to represent households
This commit is contained in:
parent
e005d8b129
commit
f50d7c1076
8 changed files with 181 additions and 2 deletions
25
src/entity/household.rs
Normal file
25
src/entity/household.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "household")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
super::household_members::Relation::User.def()
|
||||
}
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::household_members::Relation::Household.def().rev())
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
46
src/entity/household_members.rs
Normal file
46
src/entity/household_members.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "household_members")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub household: Uuid,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub user: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::household::Entity",
|
||||
from = "Column::Household",
|
||||
to = "super::household::Column::Id",
|
||||
on_update = "Restrict",
|
||||
on_delete = "Restrict"
|
||||
)]
|
||||
Household,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::User",
|
||||
to = "super::user::Column::Id",
|
||||
on_update = "Restrict",
|
||||
on_delete = "Restrict"
|
||||
)]
|
||||
User,
|
||||
}
|
||||
|
||||
impl Related<super::household::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Household.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
@ -2,4 +2,6 @@
|
|||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod household;
|
||||
pub mod household_members;
|
||||
pub mod user;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
pub use super::household::Entity as Household;
|
||||
pub use super::household_members::Entity as HouseholdMembers;
|
||||
pub use super::user::Entity as User;
|
||||
|
|
|
|||
|
|
@ -16,4 +16,13 @@ pub struct Model {
|
|||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl Related<super::household::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
super::household_members::Relation::Household.def()
|
||||
}
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::household_members::Relation::User.def().rev())
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue