Skip to main content
What is a data model?

The data required for an application is defined in its data model. Individual models use properties and relations to describe data stored.

Updated over 3 months ago

Data models provide the structure for the application data. A data model consists of multiple models, properties, and their connections (relations):

Models, properties and relations at Betty Blocks

Check out this theory video about data models:

Models

Models represent real-world objects that can be uniquely identified. A model exists either physically (car) or logically ( as a concept).

The name of a model is written as a singular noun. Every new application starts automatically with two models: Role and User.

Properties

Properties are the attributes ascribed to a model and are assigned a data type. This defines the property information - data - in terms of, for example, a number, text (string) or price type.

Each new model automatically contains the properties:

- created at

- updated at

- Id.

The Id property uniquely identifies every object in a model.

Relations

Models can be related to one another using relations.

Relations are the connections between models. For example, Customers and Orders are related models.

One Customer could have multiple Orders and a single Order is related to one Customer. The relation type indicates the number of related objects in a model. Relations are based on the data connected via models and can be either:

- has many,

- belongs to and has

- belongs to many

Models: Role of models in a data model

Models initially represent details about what the application contains and how it is organized. The information in a model is expanded to provide details about data types, and the relationships among entities. In its final stage the data model through individual models provides the schema that details how information is stored in the database and details the primary and foreign keys that re used to maintain relationships among entities.

Creating models

You can create new models from the:

  • Data model quick menu using the Add button [+]

  • Visual interface (Schema view) and the Data model list overview by clicking on the New model button.

The following example explains how you create a new model window from the Data model list overview:

Data model overview

1. Click on the New model button. The Create new model pop-up window is displayed.

2. Apply an appropriate name for the model (A). Use the singular form when applying a name. Once applied, the Create model button can be selected.

3. Click on the Create model button. The model is created as shown in the example with the name as assigned (A). By default, the following properties are included in all models:

  • Created at

  • ID

  • Updated at

You can use the New property button to assign the additional properties for building the data connections that you require for your application.

Properties: Role of properties in models

A model contains a series of properties. Properties point to data. What kind of data is stored depends on the data type which can be a number, text, image, file, etc.
โ€‹

When you create a model, default properties are applied to the model Created at, Updated at and Id . These initial properties provide unique identifiers. Additional properties can be added as required to a model.

Viewing the properties in a model

The following example contains an overview of the role model with additional properties:

A data model overview

The following are some of the details displayed in the columns in the properties table:

A. The name of the properties is displayed in this column.

B. The name applied for the property in the database. This name is based on details provided when creating a model.

Note: This name can be used when defining an application programming interface (API) or when developing custom actions.

C. Whether or not a default value is set. You can click on the property row to open the details for the property to set the default value settings for the individual property.

Tip! Use the Back button to return to the previous view.

Relations: How relations are used for connecting models

Relations represent the connection between the models. The relation type determines the connection between individual models. Models call out to each other through a relation.

Models can have one or more different types of connections. The following lists the different relation types, describes the connection and provides an example of when it can be used:

Belongs to (many sources belong to one target)

Multiple objects as defined in the source model are related to a single object as defined by the target model.

Multiple source objects are related to a single target object. The source model obtains a new object property that will store an object of the target model, the target model obtains a new collection property that stores multiple objects of the source model.

Many tasks are assigned to one Team.

Many players belong to one team.

Many orderlines make up one order.

Has many (single source has many targets)

This means that one object of the source model is related to multiple objects of the target model. The source model obtains a new collection property that stores multiple objects of the target model.

The target model obtains a new object property that stores an object of the source model.

A project has many tasks.

A movie has many actors playing in it.

A pizza is made out of many ingredients.

Has and belongs to many (One source has and belongs to many targets)

This is a many to many relation. Multiple objects of the source model are related to multiple objects of the target model.

The source model obtains a new collection property that stores multiple objects of the target model.

A student takes many classes.

A movie involves many actors playing in it.

An author can write multiple books but a book can also be written by many authors.

A user can have multiple roles and those roles can also be applied to multiple other users.

Self-Referencing Relationships

These types of relationships involve only a single model.

Team roles in organisations - for example, an Employee model that represents the employees in an organisation. Various employees can be assigned as supervisors or team leaders for multiple employees.

An employee is an employee of an organisation and simultaneously the supervisor of multiple employees.

A user can have multiple roles and those roles can also be applied to multiple other users.

Viewing relations between models

The following provides an example of how the relation between models in the visual interface (schema view) is represented when working with Data model module.

Data model's schema view

A. The default Role and User models are displayed in the initial view for all new applications. You can click on a model name to navigate to the details for an individual model.

Note: You can return to the schema view by clicking on the back button.

B. When you hover over a model in the schema view, a scroll bar is displayed for scrolling through the properties that are defined for a model. You can click on a property or relation to display detailed information. The detailed settings are displayed in a separate pane. You can apply new details or change existing details as required.

C. You can use the Zoom buttons to scale the visible display to between 50% to 200%. For example, press to reduce the display to 50%. You can use the Reset button that is displayed when you hover over the Zoom buttons to reset the display to 100%.

D. You can switch the details for properties On/Off. In the above example, the properties details button is On. As shown, properties for each model are displayed. As you create additional models, this feature can be useful when you want to quickly check the properties included in a data model. When the properties key is switched to Off, only the model name is displayed.

โž Next article: What are settings models?

Did this answer your question?