How do I store data in pairs

I’m creating a recipe directory and as data types I have Recipes and Ingredients, and Recipes have lists of Ingredients.

The challenge is that I don’t just need to store Ingredients, I need to store Ingredients and a quantity for each Ingredient, which is just a number. Can I have a list of pair values on a data type like Recipe?

The workaround I’m using right now is another data type, “Ingredient and Qty”, which has an Ingredient and a number for quantity, and the Recipe has a list of these. However, I’d rather not have to create a new data type here.

I have thought about letting Recipe have a list of Ingredients and a list of numbers, but I’m afraid it’ll be too difficult or unpredictable to make sure they remain in sync in terms of order.

Is there a standard way to just store a list that contains two values per item, or some other way to do this that doesn’t require an extra data type?

Thanks!

You can always just use a text line with the date like “1 tsp refined sugar”. You can also use a list of texts to hold the entire ingredient list per recipe this way.

Unless you want to have different ingredients that can be used in multiple recipes. Then your current method makes more sense. with your current way you’d be able to search for recipes containing specific ingredients, which would be a lot slower with the text method.

Unfortunately, I haven’t found a way to store “pairs” cleanly in Bubble. Your method seems to be the way to go right now.

I think for most purposes having a separate datatype for ingredient_quantity is the way to go (simpler to manage, probably faster to load and easier to display and sort etc.)…

But you can always just use a list of texts such as “ingredient:quantity” and then use the ‘split by’ operator to separate the ingredient and the quantity. (split by :)

If your Ingredients are a datatype themselves, then you could use the unique ID and the quantity in the text, separated by : (or any other character).