Infinable Docs

Data Model for Beginners

Learn the basics of data models
A Data Model lets you create/update/delete data that will be used in your apps. For example, you can create a product data source where you will store a collection of products. You will then be able to display a list of products in your app or let the users create a new product, buy a product...
A data source is like a database where content can be stored and referenced throughout an app dynamically. Different data sources signify different content types, and an individual piece of content within a data source is called a data record. For example, you can have a data source of blog posts, authors, clients, projects, ... For an e-commerce app for example, you would have data sources for products and categories.
Data sources are composed of fields that define the properties of the data records that it will contain. Data source fields aren't website elements. They are simply fields where data is stored for each record, which you’ll be able to reference in the pages of your application.
To structure a data source, you can choose between different types of fields for dynamic content:
  • Plain Text: basic text that doesn't need formatting like inline styles...
  • Rich Text: long text that needs some formatting (e.g. a blog post)
  • Option: text that must be chosen within a predetermined list of options (e.g. for a User data source, the status can be an option with 2 possible values: ADMIN or CLIENT)
  • Number: numeric value
  • Yes/No: boolean value, a field which can have either of two values: Yes or No
  • Date/Time: date and time
  • Email: email address
  • Phone: phone number
  • Password: password that will be hashed securely
  • Color: used to specify a color using a color picker
  • Url: external url (e.g. link to facebook page)
  • Geographic Address: a geographic address will contain information about a given location (country, country code, locality, address, latitude, longitude)
  • Image: external or internal image
  • File: external or internal file
  • Relation: a relation field is used to reference another data collection and associate one item with one or more item(s)

What are the different types of relations?

Relationships play a central role in a data model as they define how your data model data sources are related to each other.
There are 3 types of relationships that can defined between data sources:
  • One-to-one: This type of relationship allows only one data record on each side of the relationship. For example, considering the AirBnB clone and Bookings and Payments data sources. A booking is associated with a single payment and a payment is associated with a single booking.
  • One-to-many (or Many-to-One): A one-to-many relationship allows a single data record in one data source to be related to multiple data records in another data source. For example, considering an AirBnB clone, we have a data model with Users and Bookings data sources. A single user can have multiple bookings, but a single booking could not be linked to multiple users.
  • Many-to-many: This is a complex relationship in which many data records in a data source can link to many data records in another data source. For example, considering Meetup business, a user can participate to multiple meetups and a meetup can have multiple participants.
We will see in the next section how to define such types of relationships when creating a new data source or updating a data source.