Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

recreate proper associations between phases and work packages

ulferts0a7e57582b72
diff --git a/app/models/project/phase.rb b/app/models/project/phase.rb
index 48286524e59..c2773d9ab02 100644
--- a/app/models/project/phase.rb
+++ b/app/models/project/phase.rb
@@ -31,7 +31,8 @@ class Project::Phase < ApplicationRecord
belongs_to :definition,
optional: false,
class_name: "Project::PhaseDefinition"
- has_many :work_packages, inverse_of: :project_phase, dependent: :nullify
+ has_many :work_packages,
+ through: :definition
validate :validate_date_range
diff --git a/app/models/project/phase_definition.rb b/app/models/project/phase_definition.rb
index e49eced060b..871040c07e5 100644
--- a/app/models/project/phase_definition.rb
+++ b/app/models/project/phase_definition.rb
@@ -38,6 +38,7 @@ class Project::PhaseDefinition < ApplicationRecord
dependent: :destroy
has_many :projects, through: :phases
belongs_to :color, optional: false
+ has_many :work_packages, inverse_of: :project_phase_definition, dependent: :nullify
validates :name, presence: true, uniqueness: true
validates :start_gate_name, presence: true, if: :start_gate?
diff --git a/spec/models/project/phase_definition_spec.rb b/spec/models/project/phase_definition_spec.rb
index ddba4df3883..ff051a69410 100644
--- a/spec/models/project/phase_definition_spec.rb
+++ b/spec/models/project/phase_definition_spec.rb
@@ -50,5 +50,6 @@ RSpec.describe Project::PhaseDefinition do
it { is_expected.to have_many(:projects).through(:phases) }
it { is_expected.to belong_to(:color).required }
+ it { is_expected.to have_many(:work_packages) }
end
end
diff --git a/spec/models/project/phase_spec.rb b/spec/models/project/phase_spec.rb
index d2f0f90df36..1ea5c7416f7 100644
--- a/spec/models/project/phase_spec.rb
+++ b/spec/models/project/phase_spec.rb
@@ -38,7 +38,7 @@ RSpec.describe Project::Phase do
describe "associations" do
it { is_expected.to belong_to(:project).required }
it { is_expected.to belong_to(:definition).required }
- it { is_expected.to have_many(:work_packages) }
+ it { is_expected.to have_many(:work_packages).through(:definition) }
end
describe ".visible" do