From 2714011f8e5f085d8b81a827f3cc48e3a49b5a07 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 7 Jan 2025 09:06:44 -0300 Subject: [PATCH] ISSUE #448: Correction at affiliation migration --- db/migrate/20240524135850_create_affiliation.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index 9d566329..81cb2863 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -24,7 +24,7 @@ def up end_date = start_date # A data inicial é quando o professor recebeu algum start_date = professor.updated_at - if professor.institution_id != institution_id && (start_date - end_date).abs > 1.month + if professor.institution_id != (institution_id && (start_date - end_date).abs > 1.month) && !professor.institution_id.nil? # Atualiza a data caso a mudança de instituição seja maior que 1 mes institutions << { institution_id:, start_date:, end_date: } institution_id = professor.institution_id @@ -34,13 +34,13 @@ def up start_date: start_date, end_date: end_date ) - else + elsif !professor.institution_id.nil? affiliation.update(start_date: start_date) end # Se for a primeira versão do professor diminui a data de start da affiliation em um mês if professor.paper_trail.previous_version.nil? - start_date = professor.updated_at - 1.month - affiliation.update(start_date: start_date) + binding.pry + affiliation.update(start_date: affiliation.start_date - 1.month) end professor = professor.paper_trail.previous_version end