What’s the “right” way to do thing-to-thing associations? I know I can add a list of things as a field in a table, store the unique id of a thing in another table, or store an entire object.
Well, storing the unique ID to reference a thing is unnecessary, as it forces you to do a search to find the actual thing later. As you say, you can add a List of Things in a field, or you can add a single Thing (I assume that’s what you mean by entire object)
There’s really no “correct” way to save and associate data in Bubble, it all depends on different needs that you have. For example, let’s say you have a data type Car, and Owner. You might save a List of Car’s to the Owner, and that way you know which cars he owns. But if you later want to check the owner of a single car, you’ll see that it requires an advanced search to get it done, because the car doesn’t “know” who the owner is – only the owner does, with his list. This could be avoided by adding an Owner to the Car in addition to the first list, to allow them to reference each other in both directions.
That’s just a simple example of how the structure of your app and expected behaviors of the user can affect your database structure in a lot of ways.
App Datatype = Car; datafield = list of owners
App Datatype = Owner; datafield = car
the datafield of car could be a list of cars if the owners owns more than one car.
This makes it so you could search for the car owner or car two different ways.
Something that I have come to realize recently is that a relational database makes it so much easier to retrieve information. It does also complicate the saving of data a bit, but is not a hard hurdle.
Also, as a relational database there is one thing that could find all other things. What this means to me is that user is that one thing that all other datatypes can be related to…this makes it easier in my mind to retrieve data by using “current user” as the datasource so that you can eliminate the need to “do a search for”. It seems to have made the retrieval of information faster in my app (the less searches and more references to data types the better I feel).
So you could do:
Datatype = User; Datafield = list of cars; Datafield = Owner (this is the current users)
Datatype= Cars; Datafield = list of users; datafield = list of owners (this assumes that each car datatype could have more than one owner…for example car is a Honda Civic and you want to see all people who own a Honda Civic)
Datatype= Owner; Datafield = list of cars; Datafield = User
Another thing that helps with retrieval of information…if you know you will need to do multiple searches of the same datatype on the same page…on page load, set a custom state to a list of that datatype and use the custom state list as the datasource when you want to filter or sort the list on the page.