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
2019-09-15 18:53:00 +02:00

12 lines
466 B
Ruby

class Nutrient < ActiveRecord::Base
belongs_to :ingredient, inverse_of: :nutrients
belongs_to :quantity
belongs_to :unit
# disabled to avoid loop with Ingredient 'validates_associated :nutrients'
#validates :ingredient, presence: true, associated: true
validates :quantity, presence: true, associated: true, uniqueness: {scope: :ingredient_id}
validates :amount, numericality: {greater_than: 0}
validates :unit, presence: true, associated: true
end