mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-12 03:00:56 +00:00
Merge pull request #24 from EETagent/candidate_parent_relations
Candidate / Parent relations
This commit is contained in:
commit
6c0e187c5e
5 changed files with 51 additions and 3 deletions
|
|
@ -28,10 +28,18 @@ pub struct Model {
|
|||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_one = "super::parent::Entity")]
|
||||
Parent,
|
||||
#[sea_orm(has_many = "super::session::Entity")]
|
||||
Session,
|
||||
}
|
||||
|
||||
impl Related<super::parent::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Parent.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::session::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Session.def()
|
||||
|
|
|
|||
|
|
@ -14,6 +14,19 @@ pub struct Model {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::candidate::Entity",
|
||||
from = "Column::Application",
|
||||
to = "super::candidate::Column::Application"
|
||||
)]
|
||||
Candidate,
|
||||
}
|
||||
|
||||
impl Related<super::candidate::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Candidate.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ mod m20221024_124701_create_parent;
|
|||
mod m20221024_134454_fill_admin;
|
||||
mod m20221025_154422_create_session;
|
||||
mod m20221027_194728_session_create_user_fk;
|
||||
|
||||
mod m20221030_133428_parent_create_candidate_fk;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
|
@ -19,6 +19,7 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(m20221024_134454_fill_admin::Migration::default()),
|
||||
Box::new(m20221025_154422_create_session::Migration),
|
||||
Box::new(m20221027_194728_session_create_user_fk::Migration),
|
||||
Box::new(m20221030_133428_parent_create_candidate_fk::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ impl MigrationTrait for Migration {
|
|||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Parent {
|
||||
pub enum Parent {
|
||||
Table,
|
||||
Application,
|
||||
Name,
|
||||
|
|
|
|||
26
migration/src/m20221030_133428_parent_create_candidate_fk.rs
Normal file
26
migration/src/m20221030_133428_parent_create_candidate_fk.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use crate::{m20221024_124701_create_parent::Parent, m20221024_121621_create_candidate::Candidate};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.create_foreign_key(ForeignKey::create()
|
||||
.name("candidate_fk")
|
||||
.from(Parent::Table, Candidate::Application)
|
||||
.to(Parent::Table, Parent::Application)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.to_owned()).await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.drop_foreign_key(ForeignKey::drop()
|
||||
.name("candidate_fk")
|
||||
.table(Parent::Table)
|
||||
.to_owned()).await
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue