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

15 lines
407 B
Ruby

class Nutrient < ActiveRecord::Base
belongs_to :ingredient, inverse_of: :nutrients, required: true
belongs_to :quantity, required: true
belongs_to :unit, required: true
validates :quantity, uniqueness: {scope: :ingredient_id}
validates :amount, numericality: {greater_than_or_equal_to: 0.0}
after_initialize do
if new_record?
self.unit ||= self.ingredient.ref_unit
end
end
end