1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/models/readout.rb
2019-12-02 23:36:33 +01:00

16 lines
756 B
Ruby

class Readout < ActiveRecord::Base
belongs_to :measurement, inverse_of: :readouts, required: true
belongs_to :quantity, required: true
belongs_to :unit, required: true
# 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