Data Models
Define your application's data structure with models
Data Models
Models are the foundation of your Appivo application. Each model represents a type of data in your application and automatically becomes a database table.
What is a Model?
A Model defines a type of business object in your application, such as:
- Customer
- Order
- Product
- Task
- Invoice
When you create a model, Appivo automatically:
- Creates the database table
- Generates CRUD operations
- Provides API endpoints
- Handles data persistence
Creating a Model
- Navigate to the Models section in the Application Builder
- Click Add Model
- Enter a name for your model
- Add attributes (fields)
- Save your model
Example: Customer Model
Model: Customer
├── Attributes (Fields)
│ ├── name (Text, required)
│ ├── email (Email, unique)
│ ├── phone (Phone)
│ └── status (Selection: active/inactive)
├── Relationships
│ └── orders (one-to-many with Order model)
└── System Fields (Automatic)
├── id (unique identifier)
├── created_at (creation timestamp)
├── updated_at (last modification)
└── ver (version for conflict resolution)
Attribute Types
When adding attributes to your model, choose from these data types:
Basic Types
| Type | Description | Example |
|---|---|---|
| Text | Short text, up to 255 characters | Name, title |
| Long Text | Extended text for descriptions | Bio, notes |
| Integer | Whole numbers | Age, quantity |
| Decimal | Numbers with decimal places | Price, rating |
| Boolean | True/false values | Active, completed |
| Date | Date without time | Birth date |
| DateTime | Date with time | Appointment |
| Time | Time without date | Start time |
Specialized Types
| Type | Description | Example |
|---|---|---|
| Validated email addresses | Contact email | |
| Phone | Phone numbers with formatting | Mobile number |
| URL | Web addresses | Website link |
| Currency | Monetary values | Price, total |
| Password | Encrypted password storage | User password |
| File | File attachments | Documents |
| Image | Image uploads with preview | Profile photo |
| Selection | Predefined options | Status, priority |
Validation Rules
Protect data integrity with validation:
| Validation | Description |
|---|---|
| Required | Field must have a value |
| Unique | No duplicate values allowed |
| Min Length | Minimum text length |
| Max Length | Maximum text length |
| Min Value | Minimum numeric value |
| Max Value | Maximum numeric value |
| Pattern | Regular expression matching |
Example: Validated Customer Model
Attribute: email
Type: Email
Validations:
- Required: true
- Unique: true
- Pattern: Must be company domain
Attribute: name
Type: Text
Validations:
- Required: true
- Min Length: 2
- Max Length: 100
Relationships
Connect models together to build complex data structures.
One-to-Many
One record in the parent model relates to many records in the child model.
Customer (1) ──────> (*) Orders
One customer can have many orders
Many-to-Many
Records in both models can relate to multiple records in the other.
Students (*) <────> (*) Courses
Students can enroll in multiple courses
Courses can have multiple students
One-to-One
Each record relates to exactly one record in another model.
User (1) ────── (1) Profile
Each user has exactly one profile
System Fields
Every model automatically includes these system fields:
| Field | Description |
|---|---|
| id | Unique identifier for each record |
| created_at | When the record was created |
| updated_at | When the record was last modified |
| ver | Version number for optimistic locking |
These fields are managed automatically by Appivo and cannot be modified directly.
Indexes
Appivo automatically creates indexes for:
- Primary keys (id field)
- Foreign keys (relationship fields)
- Unique constraints
You can add custom indexes for frequently searched fields to improve query performance.
Best Practices
Naming Conventions
- Use clear, descriptive names
- Use singular nouns (Customer, not Customers)
- Avoid abbreviations unless widely understood
Design Principles
- Normalize data: Avoid storing the same information in multiple places
- Plan relationships: Think about how models connect before building
- Set validations early: Define rules from the start
- Index search fields: Add indexes for frequently queried fields
Common Patterns
Reference Data Create models for lookup values:
Model: Status
- name (Text)
- display_order (Integer)
Audit Trail Track changes with audit models:
Model: ActivityLog
- action (Selection: create/update/delete)
- model_name (Text)
- record_id (Text)
- user (Reference to User)
- timestamp (DateTime)
Next Steps
- Quick Start - Build your first application
- Data Modeling Guide - Advanced modeling techniques
- Widgets - Display and edit your data