diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-16 18:10:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-16 18:10:52 +0300 |
commit | 0552020767452da44de2bf5424096f2cb2ea6bf5 (patch) | |
tree | 9579d9f0ad3c730c33883130ec23420e80d1c5dc /app/validators | |
parent | e3748b81ca29b24197276767e245158d8f84fda3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/nested_attributes_duplicates_validator.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/app/validators/nested_attributes_duplicates_validator.rb b/app/validators/nested_attributes_duplicates_validator.rb index b60350a6311..de219c300ba 100644 --- a/app/validators/nested_attributes_duplicates_validator.rb +++ b/app/validators/nested_attributes_duplicates_validator.rb @@ -25,11 +25,11 @@ class NestedAttributesDuplicatesValidator < ActiveModel::EachValidator def validate_duplicates(record, attribute, values) child_attributes.each do |child_attribute| duplicates = values.reject(&:marked_for_destruction?).group_by(&:"#{child_attribute}").select { |_, v| v.many? }.map(&:first) - if duplicates.any? - error_message = +"have duplicate values (#{duplicates.join(", ")})" - error_message << " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend - record.errors.add(attribute, error_message) - end + next unless duplicates.any? + + error_message = +"have duplicate values (#{duplicates.join(", ")})" + error_message << " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend + record.errors.add(attribute, error_message) end end # rubocop: enable CodeReuse/ActiveRecord |