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
cryptogopher 3ebc2f58d0 Finished CSV import
Fixed problem with excessive validation
2019-09-22 20:26:07 +02:00

15 lines
408 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_thani_or_equal_to: 0.0}
after_initialize do
if new_record?
self.unit ||= self.ingredient.ref_unit
end
end
end