Quick question about linking across data types

I’ve finally worked out how to link data types and have a design for my database on paper that I’m creating on screen.
Now it comes to linking data types (aka ‘tables’ in my mind) I have a basic question…

I have a Products table in which I have a field for ProductID that uniquely identifies each product. It’s set to Type = Number.
That field will link to an Orders table that will log the products as they’re ordered by my Customers. I therefore have a field in the Orders table called ProductID and have set the data type to Products to link it to the Products table.
I’ve now started wondering if the ProductID field in the Products table should be set to type = Orders to identify each end of the link to Bubble or is Bubble clever enough to work out that ProductID = Number in Products table will for the link to ProductID = Products in the Orders table.
Also, should I set the ProductsID in the Products table to being a ‘primary field’?
Hope that makes sense and I’d be very grateful if anyone can anyone shed any light on it?

Many thanks

I have found that in Bubble, it helps to “forget” conventional DB concepts. Instead of worrying about the PK and FK and so on, Bubble takes care of all that. All you do is set a field of the parent type to either a primitive type or another custom type. Do not fiddle with the actual UIDs. Simply do things like: type Post has a field Comments, which is a list of type Comment, and type Comment has a primitive field text.

In your case, just add a field to type Product, of type Order. Also give some thought to inverse linking (store parent Product in child Order) and/or parallel linking (third new type ProductOrder which has fields Product and Order). Depending on the complexity of your Product and Order types, one of these may work better for you than others.

2 Likes