Как добавить собственную ссылку в таблицу рецептов, чтобы разрешить субрецепты? - PullRequest
0 голосов
/ 13 июня 2018

Мне нужна таблица рецептов, которая содержит список ингредиентов, а также список вспомогательных рецептов, например:

#recipe yellow lemon juice
Ingredient         unit cost  quantity
1.Yellow lemon       Kg    1.7  1
2.--suppose it has ingredient 2
3.--suppose it has ingredient 3

#recipe mayonnaise
Ingredient                  unit cost  quantity
1.olive oil                 Lt  $2.5    1   
2.egg                       Kg  $2.5    0.12    
3.mustard                   Kg  $1.59   0.01    
4.salt                      Kg  $.9     0.01    
5.RECIPE yellow lemon juice Lt  $1.9   1 ------------this one is a recipe 

Как я могу сказать, что в рецепте майонеза используется рецепт желтого лимонного сока?У меня есть следующее, но я не знаю, как разрешить подрецепты в таблице рецептов

Теперь может быть так, что у меня есть 3 рецепта A,B,C и рецепт A имеет несколько ингредиентов, но также включает рецепты Bи C

здесь - скрипка

Create table recipe
(
    recipe_id int primary key,
    recipe_name varchar(30)
); 
Create table ingredient
(
    ingredient_id int primary key,
    ingredient_name varchar(30),
    ingredient_cost float
);
Create table food_ingredient
(
    fk_recipe int not null,
    fk_ingredient int not null,
    measure float,
    unit_of_measurement varchar(30)
);
INSERT INTO ingredient VALUES 
(1,'olive oil',2.5),
(2,'egg',2.5),
(3,'mustard',1.59),
(4,'salt',0.9),
(5,'lemon ingredient 1',1.9),
(6,'lemon ingredient 2',1.9),
(7,'lemon ingredient 3',1.9);


INSERT INTO recipe VALUES
(100,'Recipe lemon juice'),
(200,'Recipe MAYONNAIse');

INSERT INTO food_ingredient VALUES 
(100,5,1.0,'Lt'),
(100,6,1.0,'Lt'),
(100,7,1.0,'Lt'),
(200,1,0.2,'Lt'),   
(200,2,0.5,'Kg'),  
(200,3,0.5,'Kg'),   
(200,4,0.2,'Kg'),
(200,5,1,'Lt');

1 Ответ

0 голосов
/ 13 июня 2018

Я бы, наверное, добавил:

   Create table dressing
(
    dressing_id int, 
    recipe_id int,
    constraint pk_dressing primary key (dressing_id, recipe_id),
    constraint fk_recipe foreign key (recipe_id) references recipe(recipe_id),
    constraint fk_dressing foreign key (dressing_id) references recipe(recipe_id)
); 

И я бы добавил немного сахара и уксуса к моему майонезу ...:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...