Sha256: dabcd3c06cc7e132d53e280870ecbb85cd2e3575c57a680da784945f112dcfda
Contents?: true
Size: 719 Bytes
Versions: 250
Compression:
Stored size: 719 Bytes
Contents
# For models that belongs_to :environment that wish to check a fields uniqueness across the org # eg. validates_with Validators::UniqueFieldInOrg, :attributes => :name module Katello module Validators class UniqueFieldInOrg < ActiveModel::EachValidator def validate_each(record, attribute, value) if value others = record.class.where(attribute => value).joins(:environment).where("#{Katello::KTEnvironment.table_name}.organization_id" => record.environment.organization_id) others = others.where("#{record.class.table_name}.id != ?", record.id) if record.persisted? record.errors[attribute] << N_("already taken") if others.any? end end end end end
Version data entries
250 entries across 250 versions & 1 rubygems