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:
Diffstat (limited to 'app/models/analytics/devops_adoption/segment_selection.rb')
-rw-r--r--app/models/analytics/devops_adoption/segment_selection.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/app/models/analytics/devops_adoption/segment_selection.rb b/app/models/analytics/devops_adoption/segment_selection.rb
index 6b70c13a773..8f95ce088a2 100644
--- a/app/models/analytics/devops_adoption/segment_selection.rb
+++ b/app/models/analytics/devops_adoption/segment_selection.rb
@@ -14,7 +14,7 @@ class Analytics::DevopsAdoption::SegmentSelection < ApplicationRecord
validates :group_id, uniqueness: { scope: :segment_id, if: :group }
validate :exclusive_project_or_group
- validate :validate_selection_count
+ validate :validate_selection_count, on: :create
private
@@ -27,9 +27,9 @@ class Analytics::DevopsAdoption::SegmentSelection < ApplicationRecord
def validate_selection_count
return unless segment
- selection_count_for_segment = self.class.where(segment: segment).count
-
- if selection_count_for_segment >= ALLOWED_SELECTIONS_PER_SEGMENT
+ # handle single model creation and bulk creation from accepts_nested_attributes_for
+ selections = segment.segment_selections + [self]
+ if selections.reject(&:marked_for_destruction?).uniq.size > ALLOWED_SELECTIONS_PER_SEGMENT
errors.add(:segment, s_('DevopsAdoptionSegmentSelection|The maximum number of selections has been reached'))
end
end