diff options
author | Etienne BaquƩ <ebaque@gitlab.com> | 2019-09-03 12:38:59 +0300 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2019-09-03 12:38:59 +0300 |
commit | a43ab8d6a430014e875deb3bff3fd8d8da256747 (patch) | |
tree | 25da7465575e53501737bb0d71709021173f7319 /app/models/milestone_release.rb | |
parent | de4e2dcafceee485cba9ef6993062b00a4929d2f (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_release.rb')
-rw-r--r-- | app/models/milestone_release.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/milestone_release.rb b/app/models/milestone_release.rb new file mode 100644 index 00000000000..c8743a8cad8 --- /dev/null +++ b/app/models/milestone_release.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class MilestoneRelease < ApplicationRecord + belongs_to :milestone + belongs_to :release + + validates :milestone_id, uniqueness: { scope: [:release_id] } + validate :same_project_between_milestone_and_release + + private + + def same_project_between_milestone_and_release + return if milestone&.project_id == release&.project_id + + errors.add(:base, 'does not have the same project as the milestone') + end +end |