Renamed Ingredient -> Food
Ingredient is now part of composition (meal/recipe/dish)
This commit is contained in:
@@ -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?
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user