When you set up a new Bubble application, a unique, encrypted relational database is set up specifically for your app. Apart from a few built-in fields, you decide exactly what the database should contain, and how data relates to each other.
Any of your data types in Bubble can have fields added to them. Data type fields are simply a spot reserved to save a specific kind of data that Bubble can recognize in the database. Fields can contain two different things:
Bubble’s built-in field types
Field name | Description |
---|---|
Text | Any kind of text, including bbcode, HTML or anything else |
Number | Numbers, including decimals |
Numeric range | The range between two numbers, such as 1-100 |
Date | A date. Always contains both date and timestamp. |
Date range | The range between two datetimes, such as January 1st 2021 00:00 and December 31st 2021 23:59 |
Yes/No | A true or false setting, often called a boolean. An empty value is returned as a NO. |
File | The URL of a file saved as text |
Image | The URL of an image saved as text |
Geographic address | A Google Maps compatible address |
Using Data Types in fields
Every Data Type that you create can be used as a field on another Data Type, to bind them together in the database. For example, your database may contain the following two Data Types:
- User
- Company
If you want to store which Company a User belongs to, you can create a new field on the User data type called Company. This way, you can save a Company stored in your database on a User and use that information to show it in your app or in a search to filter out User belonging to a specific Company.
Saving a List of Things in a field
Sometimes you may need to store more than one thing, For example, the User from the last example may belong to only one Company, but several Teams. In Bubble, fields that contain more than one Thing is known as a list. In traditional coding, this is often referred to as an array.
When you create a new field in Bubble, you check the This field is a list (multiple entries) checkbox to tell Bubble that this field should contain more than one Thing:
Lists and Privacy Rules
Bubble’s way of handling security with Privacy Rules can be a bit confusing, and at worst can open up for potential security issues in your app. A common misunderstanding I see from new developers is the Find in searches option, which determines whether a Thing should be made available to a User or not.
In the example below, only Users who are logged in should be able to find this particular thing in a Search.
It’s important to note the word Search here: When you perform a search in Bubble, it’s done in the following sequence:
- Search request received by server
- Privacy Rules applied
- Other Conditions applied
- Results returned to browser
As you can see, Privacy Rules are applied as an extra condition before other conditions are applied, and thus restricts forbidden data to every leave the server. When you use lists on the other hand, all of the content of the list will be downloaded to the browser when the Thing is loaded regardless of whether it’s protected by Privacy Rules. Thus, as a general rule, lists should only be used to store non-private information.
Note that this applies to finding the Thing in a list in general: hidden fields, attached files and auto-binding privileges still apply.
Bubble field type FAQ
What are field types in Bubble?
Field types are used to store different types of information in the Bubble database.
There are ten built-in types that can store information such as text, dates, numbers and URLs. You can extend fields to contain references to other Things stored in the database, and even to store a List (array) or Things.
Can I set up custom fields?
Yes. A field can contain any Bubble Thing as its field type. You can use this to set up a custom field.
For example, you may want to connect a User to the Company he works in. In that case, you would set up a Data Type called Company, and then set up a Field on the User where you pick the newly created Company Data Type as the field type. You can use this to show which Company a User belongs to, or in database searches, such as finding all Users belonging to a specific company.
How many fields can I save on a Thing?
There’s no limit to how many fields you can save on one Thing, but you should keep in mind that adding a lot of fields can lead to Bubble’s performance slowing down. For each field that you add, Bubble needs to go through more information and the total download size of each record will increase.
2 Comments
What are the benefits of using data type fields in Bubble applications, and how can they be used to establish relationships and organize data within the application’s database?
Hi there. It’s not really mostly about being beneficial: data type fields are how you establish relationships. If you come from a traditional database background you are probably used to “tables” (data types) using primary and foreign keys to set up relationships: in Bubble this is handled automatically by setting a data type for a given field. Under the hood, Bubble handles it in the same way (with primary/foreign keys), but the visual editor simplifies it to make it easier for those who don’t have a database background.
The “Unique ID” field that’s automatically added to new data types is the key, but you only occasionally need to reference this directly.