Fix position validation [SCI-11050]

This commit is contained in:
Martin Artnik 2024-09-13 15:17:32 +02:00
parent 98415c0d8d
commit d6ca444f4a

View file

@ -28,9 +28,9 @@ class StorageLocationRepositoryRow < ApplicationRecord
end end
def ensure_uniq_position def ensure_uniq_position
if StorageLocationRepositoryRow.where(storage_location: storage_location) if storage_location.storage_location_repository_rows
.where('metadata @> ?', { position: metadata['position'] }.to_json) .where("metadata->>'position' = ?", metadata['position'].to_json.gsub(',', ', '))
.where.not(id: id).exists? .where.not(id: id).exists?
errors.add(:base, I18n.t('activerecord.errors.models.storage_location.not_uniq_position')) errors.add(:base, I18n.t('activerecord.errors.models.storage_location.not_uniq_position'))
end end
end end