Best way of implementing 1 to N relation of things

Hi everybody

After doing my first “big” app with Bubble I am wondering about the best way to implement relation with things.

Let’s take an example with my app, I have one class of things called “Project” and another colled “ProjectStage”.
Obviously, one Project have many ProjectStages related to it (and only it, one ProjectStage is related to only one Project). ProjectStage contains informations such as startDate, endDate.

From here, there are 2 ways of implementing the data

  • Solution 1 - Projects have a field ListStage which is a list of ProjectStage
  • Solution 2 - ProjectStage have a field called Project which refer to a Project thing

Doing the project I was wondering of the most efficient way, and even sometimes changed the implementation to finally come back to the original (solution 2).

In other usecase (a messaging feature), I even implemented solution 1 and 2 at the same times, which requires a bit of attention to keep data integrity.

I wonder which is the best practice in terme of logic and in terms of performance.

Solution 1 advantage is that it is a bit more direct to access Projects list of stages (calling directly the thing instead of doing “Do a search for ProjectStages…”)

Solution 2 has other advantage. For exemple getting a list of projects regarding filters based on ProjectStage cant be more direct and server-side only while Solution 1 would require an “advanced” filter.

What is your experience?

HI @vlebert

I would always go for solution 2. There isn’t much known about Bubble performance optimisation, but using “do a search” instead of a list, is one of the important things to do. The “list of” can be used if your list is not greater than 10 or so, but the “do a search” already gives you opportunity for filtering things which is needed in most cases.

so in my opinion it is clearly solution 2.

If some other Bubbler debunks my way of working, feel free! :wink:

Hi,

To come back to my example of Projects and ProjectStages, when I create a new Project I need to copy a bunch (~50 - 100) of ProjectStages related to it.

In solution 1, I can copy a list of ProjectStage and assign them to the list field on Project

In solution 2 I need to copy a list of ProjectStage and change a value on each ProjectStage to link them to the new Project. This operation seems more heavy and there a moment when the new ProjectStage are related to the wrong Project.

This is the main reason that makes me hesitate between the 2 options.