How is it possible to create a relationship like this:
Imagine a restaurant. Among their datatables is one for recipes and one for ingredients. And there is another one, which contains categories of food such as dinner, lunch, breakfast, dessert, soup. Let’s name it cat_food.
The cook wants to sort recipes and ingredients by using cat_food. For example there is a ‘ManyToOne’ relationship from recipes to cat_food among all the other columns. So one recipe has one category and one category has several recipes.
But the cook also wants to sort the ingredients that way. Here we would have a ‘ManyToMany’ relationship, while we can use one ingredient in a dessert recipe just like in a dinner or soup recipe as well.
One solution could be to create a cat_food table for recipe and ingredients for its own. But how is it possible to create the cat_food table, which stores either recipes or ingredients?(depends on what is given)
My thought is to use an intermediate model and set both ‘foreignKeys’ with the field options ‘blank=True’ and ‘null=True’. But I am not satisfied with that. Is it possible that it can cause some database problems on the long term? Is there a more elegant way to handle such a situation?