A Model in Gadget represents a data structure that defines the shape of the data stored in the Gadget database (powered by Postgres). It consists of fields, relationships, and validations that can be used to build data models for your application.
Models in Gadget are similar to tables in traditional SQL-based relational databases.
How models work
Models operate within the database to define the structure and rules for storing data. Gadget's built-in database is relational, which means it stores data in rows within tables. In Gadget, rows are referred to as records, and tables are called models.
How to create models
The process of creating models is structured by utilizing fields, validations, and relationships. Models serve as the blueprint for organizing and representing data in an application or system.
Fields are the individual components within a model that define the attributes or properties of the data being stored. These fields can represent various types of data, such as strings, numbers, dates, or booleans, allowing for flexibility in data representation. Validations are an extension of fields containing rules and constraints applied to the fields to ensure the integrity and correctness of the data. They enable developers to enforce specific criteria, such as data type, length, presence, uniqueness, or custom conditions.
Relationships can then be used to establish connections between different models, enabling the representation of complex associations and dependencies. These relationships can be defined as Belongs To, Has One, Has Many, Has Many Through, providing a structured way to navigate and query related data. By combining fields, validations, and relationships, developers can create robust and organized models that accurately represent and manipulate data within their applications.