# Models
In the CyberOcean Cloud framework, models play a crucial role in representing and managing data. Models define the structure of the data in the MongoDB database and are utilized by a custom ORM for efficient data handling.
# Creating a New Model
To create a new model in the CyberOcean Cloud, you need to define its structure and relationships. This process involves specifying the model's name, attributes, and any relations it has with other models.
# Model Configuration
Name (Required):
- Format: PascalCase
- Description: This is the name of your model. It should be in PascalCase (e.g.,
UserDetail
,ProjectData
). - Example:
"model": "Project"
Attributes (Required):
- Format: List of Strings
- Description: These are the fields within your model. Each attribute represents a column in the MongoDB collection.
- Example:
"attributes": { "title": "", "description": "", ... }
Relations (Optional):
- Format: List of Strings
- Description: If your model has relations to other models, they should be defined here. Relations help in establishing connections between different models, such as one-to-one, one-to-many, etc.
- Example:
"relations": { "iconId": { "type": "BELONGS_TO", "model": "Media", ... } }
# Model File Structure
When defining a model, you will create a JSON configuration file with the following structure:
- model: The name of the model in PascalCase.
- table: The name of the table in the database. It should be plural and lowercase.
- attributes: An object that lists all the attributes of the model.
- options (Optional): Additional options for the model, including relations.
# Example Model Configuration
{
"model": "Project",
"table": "projects",
"attributes": {
"version": "1.0.0",
"title": "",
"description": "",
"hours": 0,
"iconId": null,
"ownerId": null
},
"options": {
"relations": {
"iconId": {
"type": "BELONGS_TO",
"model": "Media",
"byId": true,
"jsonField": "icon"
}
}
}
}
# Output Format and Location
- Format: JSON
- Location: The model configuration should be saved in the
@/config/database/models/
directory with a file name matching the model name, e.g.,Project.jsonc
.
Hooks →