I’m not able to figure out how to do this:
- I have a table of inventories.
- I have a table cities.
- I have a table of people.
There’s many people per city, and many inventories per city. Here we limit to one type of item (box), so effectively one inventory.
Goal: When triggered, I want to removed 1 item from the inventory per people related to that inventory, only if there’s enough for everyone.
Adding a diagram to explain more easily:
So I did:
Things to change:
Make change to a list of inventories > search(inventories, where item is box):
Variable to change:
Quantity = This inventory’s quantity - search(population, where population’s city is this inventory’s city):count.
Condition for change:
…well that’s where I’m stuck. I cannot reference the “this inventory” as above, if I could I would do something like, only when this inventory’s quantity >= search(population, where population’s city is this inventory’s city):count.
Still I have only resolved a part of that problem, because then I need to move the quantity to each people as well.
I tried so many things: comparing two lists of inventories, comparing a list of inventory against a list of people, i even tried to bring a list of cities and work from there, I tried using :intersect, :filter, :group_by etc. I’m just out of options. This stuff is really intuitive.
I think in pseudo-code I need to change a list of inventories I = {ia … in}, where I is findAll(inventory).filtered(quantity ≥ findAll(people).filtered(city = i.city).count())
I’m trying to understand the Bubblogic here
How do I achieve my goal here? Help.