Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtienne BaquƩ <ebaque@gitlab.com>2019-09-03 12:38:59 +0300
committerAndreas Brandl <abrandl@gitlab.com>2019-09-03 12:38:59 +0300
commita43ab8d6a430014e875deb3bff3fd8d8da256747 (patch)
tree25da7465575e53501737bb0d71709021173f7319 /app/models/milestone.rb
parentde4e2dcafceee485cba9ef6993062b00a4929d2f (diff)
Added relationships between Release and Milestone
Modified schema via migrations. Added one-to-one relationship between the two models. Added changelog file
Diffstat (limited to 'app/models/milestone.rb')
-rw-r--r--app/models/milestone.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index 2ad2838111e..101e963ea29 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -24,6 +24,12 @@ class Milestone < ApplicationRecord
belongs_to :project
belongs_to :group
+ # A one-to-one relationship is set up here as part of a MVC: https://gitlab.com/gitlab-org/gitlab-ce/issues/62402
+ # However, on the long term, we will want a many-to-many relationship between Release and Milestone.
+ # The "has_one through" allows us today to set up this one-to-one relationship while setting up the architecture for the long-term (ie intermediate table).
+ has_one :milestone_release
+ has_one :release, through: :milestone_release
+
has_internal_id :iid, scope: :project, init: ->(s) { s&.project&.milestones&.maximum(:iid) }
has_internal_id :iid, scope: :group, init: ->(s) { s&.group&.milestones&.maximum(:iid) }
@@ -59,6 +65,7 @@ class Milestone < ApplicationRecord
validate :milestone_type_check
validate :start_date_should_be_less_than_due_date, if: proc { |m| m.start_date.present? && m.due_date.present? }
validate :dates_within_4_digits
+ validates_associated :milestone_release, message: -> (_, obj) { obj[:value].errors.full_messages.join(",") }
strip_attributes :title