Noob - thing inside a thing?

Hi @qooqu, welcome!

In classical database terms, this would be a one-to-many relationship (one country can have mane cities, but a city can only belong to one country). In Bubble, the definition is a bit different, but the mechanics are the same.

  1. Create data tyoe country
    You already have a data type called City, and you can now add another one called Country, with a name field (and vote, if you want to vote for countries as well)

  2. Add Country to City
    Go into the City data type, and add a new field. In the list of field types, you pick Country. When this is added, you can add a Country to the City, meaning you have specificed which Country the City belongs to.

  3. Add Cities to Countries
    Now you need to repeat this action, but with a small twist. You do the vice versa of the above, and add City to the Country data type instead, but this time check the box This field is a list. By doing this, you can add not just one, but several cities. In other words, the country will include a list of the cities that belong to it.

When this is done, you can access the data both ways: you can look up a city and see which city it belongs to, and you can look up a country and see a list of cities that belong to it.

6 Likes