Class: Katello::Validators::RootRepositoryUniqueAttributeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/lib/katello/validators/root_repository_unique_attribute_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
# File 'app/lib/katello/validators/root_repository_unique_attribute_validator.rb', line 4

def validate_each(record, attribute, value)
  exists = RootRepository.where(:product_id => record.product_id, attribute => value).where("id != ?", record.id || -1).exists?

  if record.send("#{attribute}_changed?") && record.custom? && exists
    record.errors[attribute] << _("has already been taken for this product.")
  end
end