1
0

Renamed Ingredient -> Food

Ingredient is now part of composition (meal/recipe/dish)
This commit is contained in:
cryptogopher
2020-04-14 19:44:19 +02:00
parent c3010a70e8
commit 8e8160c41a
46 changed files with 204 additions and 199 deletions

View File

@@ -1,4 +1,4 @@
class Ingredient < ActiveRecord::Base
class Food < ActiveRecord::Base
enum group: {
other: 0,
dish: 1,
@@ -16,7 +16,7 @@ class Ingredient < ActiveRecord::Base
belongs_to :ref_unit, class_name: 'Unit', required: true
belongs_to :source, required: false
has_many :nutrients, inverse_of: :ingredient, dependent: :destroy, validate: true
has_many :nutrients, inverse_of: :food, dependent: :destroy, validate: true
validates :nutrients, presence: true
accepts_nested_attributes_for :nutrients, allow_destroy: true, reject_if: proc { |attrs|
attrs['quantity_id'].blank? && attrs['amount'].blank?

View File

@@ -0,0 +1,6 @@
class Meal < ActiveRecord::Base
belongs_to :project, required: true
has_many :ingredients, as: :composition, dependent: :destroy
has_many :foods, through: :ingredients
end

View File

@@ -1,8 +1,8 @@
class Nutrient < ActiveRecord::Base
belongs_to :ingredient, inverse_of: :nutrients, required: true
belongs_to :food, inverse_of: :nutrients, required: true
belongs_to :quantity, required: true
belongs_to :unit, required: true
validates :quantity, uniqueness: {scope: :ingredient_id}
validates :quantity, uniqueness: {scope: :food_id}
validates :amount, numericality: {greater_than_or_equal_to: 0.0}
end