diff --git a/changelog/67_UNRELEASED_xxxx-xx-xx.md b/changelog/67_UNRELEASED_xxxx-xx-xx.md index 95ff795f..0c8d5fc9 100644 --- a/changelog/67_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/67_UNRELEASED_xxxx-xx-xx.md @@ -19,6 +19,7 @@ - Fixed that consuming recipes was possible when not all ingredients were in-stock (and this potentially consumed some of the in-stock ingredients; not matching the message "nothing removed") - Fixed that the price of the "Produces product"-product, which is added to stock on consuming a recipe, was wrong (was the recipe total costs multiplied by the serving amount instead of only the recipe total costs) - Fixed that calories of recipe ingredients were displayed with an indefinite number of decimal places +- Fixed that ingredient amounts were wrong for multi-nested (> 2 levels) recipes, when the included recipe used an serving amount other than 1 ### Meal plan diff --git a/migrations/0174.sql b/migrations/0174.sql new file mode 100644 index 00000000..ac72538a --- /dev/null +++ b/migrations/0174.sql @@ -0,0 +1,26 @@ +DROP VIEW recipes_nestings_resolved; +CREATE VIEW recipes_nestings_resolved +AS +WITH RECURSIVE r1(recipe_id, includes_recipe_id, includes_servings, level) +AS ( + SELECT + id AS recipe_id, + id AS includes_recipe_id, + 1 AS includes_servings, + 0 AS level + FROM recipes + + UNION ALL + + SELECT + rn.recipe_id, + r1.includes_recipe_id, + CASE WHEN r1.level = 0 THEN rn.servings ELSE (SELECT servings FROM recipes_nestings WHERE recipe_id = r1.recipe_id AND includes_recipe_id = r1.includes_recipe_id) END AS includes_servings, + r1.level + 1 AS level + FROM recipes_nestings rn, r1 r1 + WHERE rn.includes_recipe_id = r1.recipe_id +) +SELECT + *, + 1 AS id -- Dummy, LessQL needs an id column +FROM r1;