Models Overview

Models organize and store data in App Maker. You can think of a model like a table in a database or a sheet in a spreadsheet. Spreadsheets organize data by columns, and store data in rows. Models organize data by fields, and store data in collections called records.

For example, imagine you work for a new startup, Weyland Corp, and you want to build an HR app that tracks employees' names, ID numbers, and dates of birth. In App Maker, you can make an Employee model with four fields: Name, EmployeeID, Active and DateOfBirth. You create a page in your app where a user can add a record to the model for each employee. In a spreadsheet, the same data is stored in columns and rows:

NameEmployeeIDActiveDateOfBirth
Carter Burke2179426False03/30/2150
Ellen Ripley1612122True01/7/2092
Two records for the Employee model

Types of models

App Maker supports five types of models:

  • Google Cloud SQL—A traditional MySQL table that can be shared among multiple applications,

    • Default—a G Suite administrator can set up a Cloud SQL instance that is shared among App Maker apps in an organization. When this is enabled, a new database is automatically created when you add a Cloud SQL data model to an app. Choose this option if your app needs a database that requires no set up and is easy to use.

    • Custom—Once your administrator sets up a default Cloud SQL instance, you can also set up your own Cloud SQL instance. Choose this option when:

      • your application serves many users or stores a lot of data.
      • the database must be shared with other applications.
      • you need to manage the database or retain control of the Cloud SQL instance.
  • Calculated—A "virtual" model that uses scripts to produce data. This model lets you manipulate data from models or other sources, but you must be comfortable writing advanced server-side scripts to set it up.

  • Calculated SQL—A query that is run against a Google Cloud SQL database.

  • Client-side calculated—A client-side query script that is run to fetch data synchronously or uses a callback to return asynchronous results.

  • Directory—A model that obtains information from your organization's directory, for example, email addresses and phone numbers.

The model editor

The model editor is where you define the structure and settings of your models. App Maker directs you to the editor after you create a model. To return to the model editor, click the model's name in the left navigation bar. The editor has up to five tabs, depending on the type of model:

  • Fields—Add new fields to a model and edit field settings. For example, you could add an Email field to the Employee model and set it as required.

  • Datasources—Define how a model retrieves and stores data when queried, including the subset of records it returns. For example, you could create a datasource for the Employee model that only returns active employees when queried.

  • Events—Create server-side scripts that run when your app displays, creates, or deletes records. For example, you could write a script for the Employee model that automatically populates the HireDate field when a user creates a new employee record. Not available for client-side calculated models.

  • Relations—Describe relationships between records within a model or across models. For example, you could create a relation in the Employee model between a manager and their direct reports. Not available for calculated models.

  • Security—Control which users can create, load, save, or delete records in a model. For example, you could restrict the Employee model so that only employees could view the records in the model.

Display Field

When you create a model, you can select the default display field. App Maker uses the default display field when it refers to a record in the model. A display field is commonly used for widgets that select a record, such as dropdowns.

For example, you might select the Department field in a Departments model that contains records of department names and their locations. When you set the datasource of a dropdown widget to the model, the dropdown options are the values of the Department field.

If you don't specify a display field, App Maker tries to find a field named "id" or "name" to display. If your model doesn't have a field with either name, App Maker uses the model's first string field.

To set a field as the default display field:

  1. Click the model.
  2. In the Fields tab, click the field that you want to set as the display field.
  3. Click Set as display field.

To change the display field to another field, open the field and click Set as display field. Only one field can be set as the display field.

To set the display field in another way, bind the names property of a widget to the field that you want to display.