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