diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index 8802b77f..609a0073 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -40,17 +40,13 @@ def up elsif professor.institution_id == institution_id || ((end_date - start_date) <= 1.month) affiliation.update(start_date: start_date) end - # Se for a primeira versão do professor pega a data da primeira tese do professor e diminui um mês - if professor.paper_trail.previous_version.nil? - if initial_start_date.nil? - affiliation.update(start_date: start_date - 1.month) - else - affiliation.update(start_date: initial_start_date - 1.month) - end - break - end professor = professor.paper_trail.previous_version end + if initial_start_date.nil? || initial_start_date >= start_date + affiliation.update(start_date: start_date - 1.month) + elsif + affiliation.update(start_date: initial_start_date - 1.month) + end institutions << { institution_id:, start_date:, end_date: } end