I have a specific question but think this will be broadly useful for anyone saving multiple ‘things’ that are related to a specific user in their application so hopefully this will help others!
I have a site that allows a specific user to save their favourite ‘posts’.
My question is what is the most optimal (performance) way to save this data in Bubble.
I’ve had a look at some SQL database design tutorials etc so was thinking of :
Each post has a unique ID in a “Post” data type which also includes the content of the post.
Add a ‘posts’ field to my “User” data type which is a list of unique ID’s of posts
When querying and returning the records, I would query “give me all the current users saved posts” - which would be the list of unique ID’s in the User data table, and then it would look those ID’s up in the Posts table?
Is this optimal or is there a better way to do it?
Hi there, @nick14… what you described (linking two custom data types together by having a field in one of the data types that references the other data type) is “basic” Bubble functionality that you should definitely take advantage of. In your example, having a posts field on the User data type that is a list of posts a user has saved is a reasonable way to go. When you need to access a user’s saved posts, the expression Current user's posts will do the trick.
Something to keep in mind, though, is that if a user might save hundreds or thousands of posts (which would make the list in their posts field quite long), you might be better off from a performance perspective if you use a custom data type to store the association between a user and each of their saved posts. You can do some searching for information on this topic, but a search through a custom data type can often be more performant than accessing a long list on another data type.