diff options
author | Etienne BaquƩ <ebaque@gitlab.com> | 2019-09-03 09:38:59 +0000 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2019-09-03 09:38:59 +0000 |
commit | a43ab8d6a430014e875deb3bff3fd8d8da256747 (patch) | |
tree | 25da7465575e53501737bb0d71709021173f7319 /app/models/release.rb | |
parent | de4e2dcafceee485cba9ef6993062b00a4929d2f (diff) | |
download | gitlab-ce-a43ab8d6a430014e875deb3bff3fd8d8da256747.tar.gz |
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/release.rb')
-rw-r--r-- | app/models/release.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/release.rb b/app/models/release.rb index 459a7c29ad0..b2e65974aa0 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -12,6 +12,12 @@ class Release < ApplicationRecord has_many :links, class_name: 'Releases::Link' + # 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 :milestone, through: :milestone_release + default_value_for :released_at, allows_nil: false do Time.zone.now end @@ -20,6 +26,7 @@ class Release < ApplicationRecord validates :description, :project, :tag, presence: true validates :name, presence: true, on: :create + validates_associated :milestone_release, message: -> (_, obj) { obj[:value].errors.full_messages.join(",") } scope :sorted, -> { order(released_at: :desc) } |