Database Structure - Splitting the User Data Type

I have been learning Bubble over the past three weeks and have a couple of questions about the database structure for a marketplace app I am building.

Both sides of the marketplace can be a User.

One is a “restaurant owner” and through their Restaurant Owner Profile data type can enter details of their restaurant which is what will populate the app for the second side of the marketplace, the “member”

Currently, I have the following Data Types and respective Data Fields:

Data Type: User - removed all privacy rules

Data Fields:

  • name (text)
  • email (text)
  • restaurant_owner_profile (Restaurant Owner Profile)
  • member_profile (Member Profile)
  • user_permission (_User_Permissions) - this is an option set with the following options: Paid, Free, Restaurant Account, or Admin

Data Type: Member Profile

Data Fields:

  • birthday (date)
  • profile_photo (image)

Data Type: Restaurant Owner Profile

Data Fields:

  • phone (text)
  • restaurant_owned (text)
  • restaurant (Restaurant)

Data Type: Restaurant

Data Fields:

  • name (text)
  • email (text)
  • phone (text)
  • website (text)
  • address (list of geographical addresses)
  • image (Restaurant Images)

Data Type: Restaurant Images

Data Fields:

  • featured image (image)
  • images (list of images)

Questions:

  1. In terms of efficiency, quickness, and scaling, does my database structure look correct for what I am trying to do?

  2. In the Data Type Restaurant Owner Profile I link the data field “restaurant” to the Data Type “Restaurant” but how do I link these two Data Types to each other so that when I use the dynamic expression “Current User’s restaurant_owner_profile’s restaurant’s name” it will return the name of the restaurant owned by the current user?

  3. Additionally, like the question above, how do I make sure that the Restaurant Images data type is linked to the correct restaurant in the Restaurant data type so that each restaurant’s images are only displayed for the restaurant they are for?
    Example:

  • Restaurant A’s images are linked to Restaurant A and can only be displayed when looking at Restaurant A
  • Restaurant B’s images are linked to Restaurant B and can only be displayed when looking at Restaurant B.

First, kudos on planning for the DB scheme. In a low-code environment, it’s a challenge to do the tedious task of setting up the DB when you can skip that and get right to excitement of building and the dopamine hit that comes along with that. (Of course you will suffer down the road but alas we make foolish decisions all the time :slight_smile: )

Just have a couple of questions (I may have missed some details):

  1. Dont you still want to privacy on the user’s email at the very least
  2. Are you sure the user (owner) to restaurant is a 1:1?
  3. Why a Restuarant Owner Profile and not the Restaurant data type directly as the 2 additional fields on the owner profile dont seem important.
  4. You seem to account for multiple locations but only addresswise; what about phone numbers, emails, hours?
  5. why a Data type for restaurant images? esp the featured should be directly on restaurant data type
  6. Your Q1: need to flesh out more what the features and search functions of the app are
  7. Your Q2: your example is exactly how you do it: "“Current User’s restaurant_owner_profile’s restaurant’s name”. Btw what’s resturant_owned filed on owner profile?
  8. Your Q3: needs clarification. on a basic level, when viewing a restaurant the image data source will be “Restaurant’s image’s images" (consider fixing confusing naming convention)

Thanks so much for the response!

  1. You make a great point. I’ll create the privacy for the user’s email and birthday

  2. This might not answer your question so I apologize if that is the case. I might not be understanding it correctly. The way I am creating the app/dashboard for the Restaurant Owner Profile, they will be able to create one restaurant listing per account. If someone owns multiple restaurants, they will need to create a second account to register the second restaurant. I plan to change this in the future but for my first build and simplicities sake, I think it would be best for a 1:1 relationship at this time.

  3. I was trying to find a way to connect the Restaurant name with the Restaurant Owner Profile and I was using the restaurant_owned data field for this. It seems like it’s not needed. I agree that phone could be listed in the User data type so I could ultimately remove the Restaurant Owner Profile all-together and link User to Restaurant with a data field “restaurant”

  4. That’s a great point. Thank you for pointing that out!

  5. With more thought, you’re absolutely right that featured_image should be on the Restaurant data type directly. The reason I created the Data Type Restaurant Images is because I am planning to allow members and restaurant owners to upload photos for each individual restaurant so I didn’t want Bubble to search through/load all of the images with a linked restaurant until it got to a certain step. For example, I have a list of restaurants view that is a vertical repeating group that shows 5 restaurants at a time and if Bubble is loading all of the images for every restaurant I believe the app would be quite slow and would take a significant amount of workload units as it scaled. From my research, I believe this is what would happen.

  6. I think my problem is within the workflow tab. I seem to understand the expression for showing the data, but I’m not quite sure how to “write” it to the database so it will appear when I try to show it.

When a new user creates an account and their user_permission is set to “Restaurant Account” they are led to a view in the app that is a bunch of inputs in a group that ask for the restaurant contact information (name, email, address, website, etc.) with a save button at the bottom.

When the save button is clicked I have a workflow that “creates a new thing” and I save the input’s value of each to the corresponding data field for the type Restaurant.

Then, in this user’s dashboard view, the initial value for each input is supposed to be what they just saved, but it doesn’t seem to save or show after I’ve left the custom state.

From that description, are you able to tell what I might be doing wrong or what I should do differently?

Thank you again for all of your help!

You’ll want a field Visibility on the Restaurant (and User) which is an option set that has options like Private, Awaiting approval, Public. Privacy rules should be configured so only Public Restaurants and Users are visible. Otherwise, you have a situation where anyone can sign up to your app and the second they sign up, any data is technically accessible even if they haven’t ‘published’ their restaurant yet.

Thank you very much for those suggestions! I thought I would need to delete all privacy rules so that users that owned a restaurant would be able to have their restaurant show in the app.

Is there a way for users to “dig around the app” and find out information about other users somehow? Like their birthday, phone number, and email address?

Anything that isn’t explicitly protected by a privacy rule can be found this way.

Great to know, thank you!

Hey! I have a quick question about displaying data within the app that I’m hoping you might be able to answer.

I removed the Restaurant Owner Profile and linked the Restaurant data type to the User data type directly. I also added a data field “restaurant_owner” that points to the User under the Restaurant data type.

Now, I’m looking for the best way to display the information that users who have the Restaurant Account user_permission have added to the database within their dashboard view.

For example, a restaurant owner adds the name of their restaurant into an input. When they come back to their dashboard I would like them to see the name they just added.

Is the following image the best way to display this information?

Thanks again!