I’m kind of stuck on this one. In this demo app I am trying to configure an easy admin for a restaurant. The flow is that Dishes have Ingredients and an ingredient can be used for one or more Dishes. This will later be used for calculating amount of ingredient needed to produce X amount of dishes etc.
Now with this setup I can create the dishes and the ingredients for that specific dish, and show related ingredients to a specific dish.
But I can’t get my head around how to make it possible to assign ingredients to more than one dish. Any guidance would be appreciated. Thanks in advance.
I would create a comma delimited list of all ingredients (or ingredient ID’s) in a column within your dish table. Then create a Split Text column to convert that comma delimited list into an array. With that array, you can create a relation from the Dish table to the Ingredients table, and vice versa. That way a dish can relate to multiple ingredients and an ingredient can relate to multiple dishes.
Something here that I am still not getting right, but playing around with it a bit.
I am trying to achieve the possibility of adding a new ingredient, and then attaching that ingredient to one or more dishes. So basically the Dish and Ingredient can be created separately, but when I create a new dish I can multi-select from list of ingredients, or create new one.
The relation in your first image is never going to work. ‘Salmon’ does not equal ‘5RwvFYKTSvCyzA4HuMrzJw’…but ‘Salmon’ does equal ‘Salmon’, etc. Relations look for matching values. You are trying trying to match the name of the ingredient to an ID,which will never happen.
I should also ask, if an ingredient can exist in multiple dishes, why do you even have a dish ID in the ingredient table?
The way I pictured it, is with a Dish table that has a list of dishes and an array of ingredients. Then the ingredients table with a list of each individual ingredient. The relation in the dish table would link the ingredient array to to the ingredient name in the ingredient table. Likewise, a relation in the ingredient table would link the ingredient name to the ingredient array in the dish table.
(This is for the future once you get this working, but I would recommend storing ingredient RowID’s instead of names in the Dish table. Then build your relations using the ID’a instead of names. Currently, if you ever change the name of your ingredient, it will break all relations that relied on that ingredient name.)