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/ingredient.rb
cryptogopher a416e1ce9b Fixed importing Foods with QuantityValue
Fixed double flash when not followed by request
Added Food#destroy error reporting
Simplified prepare_meals with no ingredients
Renamed scope on item with subitems: subitems -> with_subitems
2020-05-20 23:33:34 +02:00

20 lines
635 B
Ruby

class Ingredient < ActiveRecord::Base
belongs_to :composition, inverse_of: :ingredients, polymorphic: true, required: true
belongs_to :food, required: true
belongs_to :part_of, required: false
has_many :nutrients, through: :food, source: :nutrients
DOMAIN = :diet
alias_attribute :subitems, :nutrients
scope :with_subitems, -> { includes(nutrients: [:quantity, :unit]) }
validates :ready_ratio, numericality: {greater_than_or_equal_to: 0.0}
validates :amount, numericality: {greater_than_or_equal_to: 0.0}
after_initialize do
if new_record?
self.ready_ratio ||= BigDecimal.new('1.0')
end
end
end