Models and Model Schemas
What is a Model Schema?
Model Schema is an object that describes all Model objects that belong to it.
You can think of it as a DB table. Model Schemas define object types that will exist in your application. They describe the properties each object can have. For example, if you want your application to manage "books", you can create a Model Schema with the name "book" that will have the properties "title" and "author" (both having the type "string"). The main function of a Model Schema is to allow you to define the structure of your data.
What is a Model?
If Model Schemas are DB tables, then you can think of Models as DB records. That's why a Model must always be associated with exactly one Model Schema.
Using the book analogy, individual books in your application will be Model objects tied to the "book" Model Schema, and you will be able to set actual values for the "title" and "author" of each book. For example, one of your models could be a record with the title "1984" and the author "George Orwell". The main function of a Model is to persist actual data in a system.
Head to the Persisting Data With Model tutorial to fully understand the process based on a TODO list example.
Model Schemas use cases
- Think of them as a custom DB table, which allows you to build highly customized features.
- Use them to group Properties, and allow the user to provide multiple values for each of them.
For example, you can build a table that will store a user's favorite books. Each book has an author, title and a number of pages. These three fields are Properties. That’s why you can use Model Schema to group Properties.
Now you can build a form that allows users to add multiple books attached to them (using GraphQL).
Soft and hard delete
Read Data Backup and Removal to get familiar with data retention and backups in platformOS.
Model Schemas are placed in the
The example below shows the BlogPost Model Schema
name: blog_post properties: - name: title type: string - name: content type: text
|name||Name of your Model Schema. Best practice is to keep it lower case. Example:
|properties||Array of properties you want to contain within your models. Equivalent to a column in a database table.||No|