I’m hoping someone knows of a more elegant way to do this. I’d like to be able to just record the idea of “5 times this thing”.
Basically, I want to mimic an associative array in Bubble.
In this case I’m letting the user build a Dish out of a list of Foods. They need to be able to record the amount of each Food in the dish. I don’t know how many Foods they’ll want to include, so I can’t hard-code fields like “food 1” and “quantity 1”.
In theory I could use two parallel lists if I could keep the index numbers synced up, but I assume that’s a bad idea.
So all I can think of is to create another thing Multi to record Food and a multiplier. So the database would look like this:
- id | 123
- name(text) | beef
- protein(num) | 25
- fat(num) | 20
- carbs(num) | 0
- name(text) | hamburger
- ingredients(list of Multi) | 987, 988, 989…
- id | 987
- item(Food) | 123 (Food, beef)
- times(num) | 250
So I’d have to create a new thing of type Multi every single time I wanted to record a quantity of a food. I assume that will work, but is there a better way?
A good example of why an array would be better is that I can’t think of a way to let the thing Multi record a multiplier against any other thing in the database without making item into text and recording just the unique id. Then I’d have to run a search for the thing with that unique id instead of it being automatically linked.
So if I’d have to create a special Multi, or at least a special field, for every different kind of thing that could be multiplied so that the field can have the correct type.
Not to mention that iterating over the list of things is of course going to cost a workflow for each and every item.