mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-19 04:18:52 +00:00
refactor: rename parent candidate fk to candidate_id
This commit is contained in:
parent
a925aa3665
commit
fd08bef4db
6 changed files with 18 additions and 18 deletions
|
|
@ -6,7 +6,7 @@ use sea_orm::*;
|
|||
impl Mutation {
|
||||
pub async fn create_parent(db: &DbConn, application_id: i32) -> Result<Model, DbErr> {
|
||||
parent::ActiveModel {
|
||||
application: Set(application_id),
|
||||
candidate_id: Set(application_id),
|
||||
created_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
updated_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
..Default::default()
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ mod tests {
|
|||
async fn test_find_parent_by_id() {
|
||||
let db = get_memory_sqlite_connection().await;
|
||||
|
||||
const APPLICATION_ID: i32 = 103158;
|
||||
const CANDIDATE_ID: i32 = 103158;
|
||||
|
||||
candidate::ActiveModel {
|
||||
id: Set(APPLICATION_ID),
|
||||
id: Set(CANDIDATE_ID),
|
||||
personal_identification_number: Set("test".to_string()),
|
||||
created_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
updated_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
|
|
@ -55,7 +55,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
let parent = parent::ActiveModel {
|
||||
application: Set(APPLICATION_ID),
|
||||
candidate_id: Set(CANDIDATE_ID),
|
||||
created_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
updated_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
..Default::default()
|
||||
|
|
@ -64,7 +64,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let parent = Query::find_candidate_by_id(&db, parent.application)
|
||||
let parent = Query::find_candidate_by_id(&db, parent.candidate_id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(parent.is_some());
|
||||
|
|
|
|||
|
|
@ -27,16 +27,10 @@ pub struct Model {
|
|||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::application::Entity")]
|
||||
Application,
|
||||
#[sea_orm(has_many = "super::parent::Entity")]
|
||||
Parent,
|
||||
}
|
||||
|
||||
impl Related<super::application::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Application.def()
|
||||
}
|
||||
#[sea_orm(has_many = "super::application::Entity")]
|
||||
Application,
|
||||
}
|
||||
|
||||
impl Related<super::parent::Entity> for Entity {
|
||||
|
|
@ -45,4 +39,10 @@ impl Related<super::parent::Entity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<super::application::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Application.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use sea_orm::entity::prelude::*;
|
|||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub application: i32,
|
||||
pub candidate_id: i32,
|
||||
pub name: Option<String>,
|
||||
pub surname: Option<String>,
|
||||
pub telephone: Option<String>,
|
||||
|
|
@ -20,7 +20,7 @@ pub struct Model {
|
|||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::candidate::Entity",
|
||||
from = "Column::Application",
|
||||
from = "Column::CandidateId",
|
||||
to = "super::candidate::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl MigrationTrait for Migration {
|
|||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Parent::Application)
|
||||
ColumnDef::new(Parent::CandidateId)
|
||||
.integer()
|
||||
.not_null()
|
||||
)
|
||||
|
|
@ -45,7 +45,7 @@ impl MigrationTrait for Migration {
|
|||
pub enum Parent {
|
||||
Id,
|
||||
Table,
|
||||
Application,
|
||||
CandidateId,
|
||||
Name,
|
||||
Surname,
|
||||
Telephone,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ impl MigrationTrait for Migration {
|
|||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.create_foreign_key(ForeignKey::create()
|
||||
.name("candidate_fk")
|
||||
.from(Parent::Table, Parent::Application)
|
||||
.from(Parent::Table, Parent::CandidateId)
|
||||
.to(Candidate::Table, Candidate::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
|
|
|
|||
Loading…
Reference in a new issue