Understanding Relational Database Nature of Bubble

Fundamentally, this is the bit that makes Bubble (and others) a bit different to a traditional relational DB. You don’t need to do it. Yes, you can set up something that looks like a foreign key, but it makes it much much more complex.

The way you “tie” A Project to many Timeslips, and a Timeslip to One Project is by embedding a particular thing in the database record.

So the TimeSlip has a field of Type ProjectData, that gets set to a particular Project. Not the key or an Id, the whole thing.

So when I add my hours, I have a dropdown of projects.

When one is selected, this dropdown’s value is the whole project thing (object, record, row … call it what you want).

So I can save it my to my TimeSlip.

Bubble is handling all that “Foreign Key” stuff for you, you don’t need to worry about how it works.

This means instead of doing Joins and stuff like that, you can use natural English to query your data.

Imagine we have a Project Manager on the Project, and we stored a User type on our Project.

If we are showing a TimeSlip, and we want to show the Name of the Project Manager.,…we can say …

This Timeslip’s Project’s Project Manager’s Name.

So we can navigate up a set of many to one relationships using just an apostrophe. Cool :slight_smile:

What about the other way round, and here we finally get to your question !

Yes, we could probably sum up all TimeSlips for every unique project, but let’s make like easier for ourselves when querying the database, by making life a little more complex when we save the data.

So I add a field to the Project called Timeslips, and make it a list.

When I save the Timeslip, I also make a change to the Project to store this Timeslip’s thing on the Project in the List.

This adds the Timeslip “thing” you just created to the list of Timeslips in the Timeslip field on Project.

This means that to do the summary of the projects, you can just go down from Project > Timeslips using this relationship.

In my repeating group, I simply list out all Projects.

And then “SUM of hours logged to that project” as you oringinally wrote can simply be added as a text field.

Almost exactly as you wrote it :slight_smile:

Yes, Bubble’s data can get more complex, but in most cases if your data query looks fairly neat and English like … your data is in good shape.

Rather that worrying about keys and normalisation of data … store your data to make it easy for YOU to retrieve.

Example working here …

23 Likes