Update things based on things from other database

Hi there.
I’m trying to create a workflow to update things based on values from other things.

The use case is as follows.
I have 3 databases:
Users - contains users and each user has a list of bets
Bets - contains an entry for bets
Events - contains football matches

Before the match starts, I’ll add an event to the DB. Then users can place a bet. Each match contains fixtures_id which should allow to uniquely identify the match within the events.
But when the match is over I need to update each bet to assign points:
3 points if the bet matches the exact score
1 point if bet matches only the winning team

How can I update all bets in bulk?

So my idea was to iterate through all bets and match them based on fixtures_id and points assignment limits using only_when field, but this does not allow me (or I don’t know how) to set condition to match bet with events.

I am assuming when you refer to database you mean tables or data types. So that you have 3 x tables/data types in your Bubble database.

So from a broad stand point you have a couple of options:

  1. In a workflow identify the records (things) you want to update and then use Make change to a list of things
  2. Create a back end workflow, and pass in the group of things, and then iterate through the list until you get to your break point.

These 2 links might be useful for you:

1 Like

Yes, I mean database as data type.

Thank you, but do you know how condition should looks? I need to compare two values from 2 things from different data types.

For pseudocode it will be:
if fixtures_id in bet = fixtures_id in Events then update bet

Well it depends on your implementation. (the devil is always in the detail).

So for a start you want to index the bets table by the Fixture type rather than the fixture id. This is counter intuitive if you are used to traditional database structures. But it is the most optimal and flexible way of doing it.

It might then have to be 2 stage:

  1. From your events return the Fixture you need (Do search for the fixture you need based upon your Events criteria)
  2. Pass that Fixture in to the query to get the Bets you want to update. And then away you go.

You could this in the same workflow, or you could split in to a backend WF and frontend workflow depending upon the details.

What do you mean? I don’t see an option to make a query other then update. Do you mean make changes to … without actually changing anything just to get a list of fixtures as part of step x?

I have no idea how to do it.

OK it sounds like you are missing some knowledge on retrieving (searching) data from your table.

The manual is a good place to start, and there are thousands of videos out there by bubble developer, which will give you something to learn by example from.

This page here will show you how to retrieve data:

What you need to be doing is to first query (search) your events table for to the correct Fixture. You then return that from the search and then take that in to the next stage where you do the actual Make changes.

I not quite follow how the flow should looks like. I though I can do everything within the workflow.
Let assume that user will click the button to trigger action. Button itself didn’t do any lookup. It can only start a workflow. What should trigger the lookup (or retrieving data from Events type)?

I only know what I want to achieve but I can implement any solution available.

Once you have triggered the workflow you can program the worlflow to take the steps I outlined for you above.

It sounds like you need to read around a little more to understand how to play with WFs and data. The link I provided will be a starting point.

Ok, what should be the first step? Which action allows me to retrieve data from type?