forked from TWS/kalkutago
Add entity and relations for user-tracks relationship
This commit is contained in:
parent
d8c9594d92
commit
7ffc176698
|
@ -25,6 +25,7 @@ services:
|
||||||
labels:
|
labels:
|
||||||
traefik.enable: true
|
traefik.enable: true
|
||||||
traefik.http.routers.kalkutago_server.rule: 'Host(`kalkutago`) && PathPrefix(`/api`)'
|
traefik.http.routers.kalkutago_server.rule: 'Host(`kalkutago`) && PathPrefix(`/api`)'
|
||||||
|
|
||||||
database:
|
database:
|
||||||
image: postgres
|
image: postgres
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -7,3 +7,4 @@ pub mod ticks;
|
||||||
pub mod track2_groups;
|
pub mod track2_groups;
|
||||||
pub mod tracks;
|
pub mod tracks;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
pub mod user_tracks;
|
||||||
|
|
|
@ -5,3 +5,4 @@ pub use super::ticks::Entity as Ticks;
|
||||||
pub use super::track2_groups::Entity as Track2Groups;
|
pub use super::track2_groups::Entity as Track2Groups;
|
||||||
pub use super::tracks::Entity as Tracks;
|
pub use super::tracks::Entity as Tracks;
|
||||||
pub use super::user::Entity as User;
|
pub use super::user::Entity as User;
|
||||||
|
pub use super::user_tracks::Entity as UserTracks;
|
||||||
|
|
|
@ -24,6 +24,8 @@ pub enum Relation {
|
||||||
Ticks,
|
Ticks,
|
||||||
#[sea_orm(has_many = "super::track2_groups::Entity")]
|
#[sea_orm(has_many = "super::track2_groups::Entity")]
|
||||||
Track2Groups,
|
Track2Groups,
|
||||||
|
#[sea_orm(has_many = "super::user_tracks::Entity")]
|
||||||
|
UserTracks,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Related<super::ticks::Entity> for Entity {
|
impl Related<super::ticks::Entity> for Entity {
|
||||||
|
@ -38,4 +40,19 @@ impl Related<super::track2_groups::Entity> for Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Related<super::user_tracks::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::UserTracks.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::user::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
super::user_tracks::Relation::User.def()
|
||||||
|
}
|
||||||
|
fn via() -> Option<RelationDef> {
|
||||||
|
Some(super::user_tracks::Relation::Tracks.def().rev())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
|
@ -25,7 +25,25 @@ pub struct Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {}
|
pub enum Relation {
|
||||||
|
#[sea_orm(has_many = "super::user_tracks::Entity")]
|
||||||
|
UserTracks,
|
||||||
|
}
|
||||||
|
impl Related<super::user_tracks::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::UserTracks.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::tracks::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
super::user_tracks::Relation::Tracks.def()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn via() -> Option<RelationDef> {
|
||||||
|
Some(super::user_tracks::Relation::User.def().rev())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
||||||
|
|
46
server/src/entities/user_tracks.rs
Normal file
46
server/src/entities/user_tracks.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 = "user_tracks")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub track_id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::tracks::Entity",
|
||||||
|
from = "Column::TrackId",
|
||||||
|
to = "super::tracks::Column::Id",
|
||||||
|
on_update = "NoAction",
|
||||||
|
on_delete = "NoAction"
|
||||||
|
)]
|
||||||
|
Tracks,
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::user::Entity",
|
||||||
|
from = "Column::UserId",
|
||||||
|
to = "super::user::Column::Id",
|
||||||
|
on_update = "NoAction",
|
||||||
|
on_delete = "NoAction"
|
||||||
|
)]
|
||||||
|
User,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::tracks::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Tracks.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::user::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::User.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
Loading…
Reference in a new issue