⚠️ This page is relevant only if you installed Forest Admin directly on a database (SQL/Mongodb). If you installed in a Rails/Django/Laravel app, you manage your models like you normally would.
Please be sure of your agent type and version and pick the right documentation accordingly.
This is the documentation of the forest-express-sequelize and forest-express-mongoose Node.js agents that will soon reach end-of-support.
forest-express-sequelize v9 and forest-express-mongoose v9 are replaced by @forestadmin/agent v1.
Please check your agent type and version and read on or switch to the right documentation.
This is still the latest Ruby on Rails documentation of the forest_liana agent, you’re at the right place, please read on.
This is the documentation of the django-forestadmin Django agent that will soon reach end-of-support.
If you’re using a Django agent, notice that django-forestadmin v1 is replaced by forestadmin-agent-django v1.
Please check your agent type and version and read on or switch to the right documentation.
Enrich your models
Declaring a new model
Whenever you have a new table/collection in your database, you will have to create file to declare it. Here is a template example for a companies table:
You can learn more about relationships on this dedicated page.
When you manually add a new model, you need to configure the permissions for the corresponding collection in the UI (allow record details view, record creation, record edit, etc). By default a new collection is not visible and all permissions are disabled. You can set permissions by going to the Roles settings.
Declaring a new field in a model
Any new field must be added manually within the corresponding model of your /models folder.
Lumber introspects your data structure recursively, so nested fields (object in object) are detected any level deep. Your sub-documents (array of nested fields) are detected as well.
Conflicting data types will result in the generation of a mixed type field.
By default all tables/collections in your database are analyzed by Lumber to generate your models. If you want to exclude some of them to prevent them from appearing in your Forest, check out this how-to.
Adding validation to your models
Validation allows you to keep control over your data's quality and integrity.
If your existing app already has validation conditions, you may - or may not - want to reproduce the same validation conditions in your admin backend's models.
If so, you'll have to do it manually, using the below examples.
Depending on your database type, your models will have been generated in Sequelize (for SQL databases) or Mongoose (for Mongo databases).
In Sequelize, you add validation using the validate property:
Mongoose has no build-in validators to check whether a string is an email. Should you want to validate that a content is an email, you have several solutions:
You can choose to add a default value for some fields in your models. As a result, the corresponding fields will be prefilled with their default value in the creation form: