Created
September 11, 2010 17:34
-
-
Save madebydna/575376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "Lookup" Tables modeled on USDA data | |
class Food | |
has_many :nutrients | |
has_many :weights | |
end | |
class Nutrient | |
belongs_to :food | |
has_one :nutrient_definition | |
end | |
class NutrientDefinition | |
belongs_to :food | |
end | |
class Weight | |
belongs_to :food | |
end | |
# ----------------------------- | |
class Recipe | |
has_many :ingredients | |
end | |
class Ingredient | |
belongs_to :recipe | |
has_many :ingredient_profiles | |
has_many :nutrients, :through => :ingredient_profiles | |
end | |
# "cache" tables, so profiles don't have to be re-created for each display | |
class IngredientProfile | |
belongs_to :ingredient | |
belongs_to :nutrient | |
end | |
# for aggregated nutrient values | |
class RecipeProfile | |
belongs_to :recipe | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ingredients should get flagged after creation depending on whether they have been found in the lookup tables:
Red flag: ingredient not found in foods table
Yellow flag: ingredient found, but not with the measurement indicated (e.g. 1 "clove" of flour)
Green flag: ingredient found and nutritionally analyzed
If ingredient gets green flag, entries will be made into the ingredient_profiles table with the nutrient_id (e.g. Kcal, Protein, Carbs) and the amount of that nutrient for the measurement of the ingredient.