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
cryptogopher 0b9401b089 Proper nested records uniqueness validation
Test pass: test_create_duplicate_for_persisted_target_should_fail
2021-04-19 00:38:28 +02:00

12 lines
465 B
Ruby

class Readout < QuantityValue
# Need to specify polymorphic association so :registry_type gets written (see
# QuantityValue for explanation why it's needed)
belongs_to :measurement, inverse_of: :readouts, polymorphic: true, required: true,
foreign_key: 'registry_id', foreign_type: 'registry_type'
# Readout uniqueness NOT validated here, see Value for explanation
validates :value, numericality: true
delegate :completed_at, to: :measurement
end