1
0

Fixed updating multiple and deleting Readouts

This commit is contained in:
cryptogopher
2019-12-02 23:36:33 +01:00
parent 7cb3ac4134
commit 8d368d6aa5
2 changed files with 19 additions and 7 deletions

View File

@@ -3,6 +3,13 @@ class Readout < ActiveRecord::Base
belongs_to :quantity, required: true
belongs_to :unit, required: true
validates :quantity, uniqueness: {scope: [:measurement_id, :unit_id]}
# Uniqueness is checked exclusively on Measurement level. Otherwise validation
# may not pass when multiple Readouts are updated at once and some quantity_id
# is moved from one Readout to the other (without duplication).
# For the same reason Readout quantity_id uniqueness has to be checked by
# Measurement when multiple Readouts are first created. Relying on this check
# only would make all newly added records pass as valid despite duplications.
#validates :quantity, uniqueness: {scope: [:measurement_id, :unit_id]}
validates :value, numericality: true
end