Data models
Understand models, records, fields, and validation.
A data model describes one kind of information in an application. A project management application might have a Project model and a Task model. Each model defines the fields that its records can contain.
Models and records
The model is the structure; a record is one instance of that structure. A Task model might define an identifier, a title, a completion flag, and a project identifier. Each individual task stores values for those fields.
{
"id": "task-101",
"title": "Review the specification",
"completed": false,
"projectId": "project-42"
}Here, task-101 identifies one task. Its title is text, completed is a boolean, and projectId identifies the project that the task belongs to.
Choose fields by meaning
- Identifiers distinguish records. Use a stable identifier rather than a name that can change.
- Text stores names and descriptions.
- Numbers represent quantities that need numeric comparison or calculation.
- Booleans represent a true-or-false state.
- Dates and times represent events such as creation or completion.
- Relationship fields connect a record to another record.
Validation
Validation describes which values are acceptable. For example, a task title can be required, a quantity can be constrained to zero or greater, and an identifier can be unique. Field type and validation serve different purposes: a value can be valid text while still failing a rule that requires the text to be non-empty.
A complete small example
A Project record can hold the project name:
{
"id": "project-42",
"name": "Website launch"
}The Task record above refers to this project through projectId. The project name stays on the Project record, so renaming the project does not require changing the title or identifier of every task.
Review a model
Check that each record has a clear purpose, fields use appropriate types, required information has validation, and related information has a clear relationship. The Model relationships page explains how to describe those connections.
