diff --git a/core/src/database/mutation/parent.rs b/core/src/database/mutation/parent.rs index f3e7ba7..3dcc2f8 100644 --- a/core/src/database/mutation/parent.rs +++ b/core/src/database/mutation/parent.rs @@ -6,7 +6,7 @@ use sea_orm::*; impl Mutation { pub async fn create_parent(db: &DbConn, application_id: i32) -> Result { 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() diff --git a/core/src/database/query/parent.rs b/core/src/database/query/parent.rs index 3e95a3e..e463d98 100644 --- a/core/src/database/query/parent.rs +++ b/core/src/database/query/parent.rs @@ -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()); diff --git a/entity/src/candidate.rs b/entity/src/candidate.rs index 9f88ce3..f90171c 100644 --- a/entity/src/candidate.rs +++ b/entity/src/candidate.rs @@ -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 for Entity { - fn to() -> RelationDef { - Relation::Application.def() - } + #[sea_orm(has_many = "super::application::Entity")] + Application, } impl Related for Entity { @@ -45,4 +39,10 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Application.def() + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/parent.rs b/entity/src/parent.rs index 0c84916..5e58d0d 100644 --- a/entity/src/parent.rs +++ b/entity/src/parent.rs @@ -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, pub surname: Option, pub telephone: Option, @@ -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" diff --git a/migration/src/m20221024_124701_create_parent.rs b/migration/src/m20221024_124701_create_parent.rs index 00d18ae..db308fd 100644 --- a/migration/src/m20221024_124701_create_parent.rs +++ b/migration/src/m20221024_124701_create_parent.rs @@ -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, diff --git a/migration/src/m20221112_112212_create_parent_candidate_fk.rs b/migration/src/m20221112_112212_create_parent_candidate_fk.rs index a2376cf..ed7f904 100644 --- a/migration/src/m20221112_112212_create_parent_candidate_fk.rs +++ b/migration/src/m20221112_112212_create_parent_candidate_fk.rs @@ -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)