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/nutrient.rb
2020-06-25 03:56:49 +02:00

14 lines
558 B
Ruby

class Nutrient < QuantityValue
# Need to specify polymorphic association so :registry_type gets written (see
# QuantityValue for explanation why it's needed)
belongs_to :food, inverse_of: :nutrients, polymorphic: true, required: true,
foreign_key: 'registry_id', foreign_type: 'registry_type'
# Uniqueness NOT validated here, see Value for explanation
#validates :quantity, uniqueness: {scope: :food_id}
validates :value, numericality: {greater_than_or_equal_to: 0.0}
alias_attribute :amount, :value
delegate :ref_amount, to: :food
end