Models
Adminmate works with the models of your ORM: Sequelize for MySQL, PostgreSQL and SQLite, Mongoose for MongoDB. The fields, types, enums, default values and relationships of your models are what the Dashboard displays and edits.
If you used the CLI, one model file has been generated per table or collection in the models/ folder, from your database schema. You are free to adapt them, or to add new ones.
Expose a model
Section titled “Expose a model”A model only appears in the Dashboard once it is listed in the models array of your configuration:
models: [ { slug: 'users', model: models.users }, { slug: 'orders', model: models.orders }]The slug identifies the model in the Dashboard (in URLs, permissions, layouts and the activity log). Use a unique value and avoid changing it afterwards.
See the Sequelize documentation for the full syntax.
module.exports = (sequelize, DataTypes) => { const Car = sequelize.define('cars', { name: { type: DataTypes.STRING }, brand: { type: DataTypes.STRING }, status: { type: DataTypes.ENUM('available', 'rented', 'maintenance') }, year: { type: DataTypes.INTEGER } }, { tableName: 'cars' });
return Car;};Composite primary keys are supported.
See the Mongoose documentation for the full syntax.
module.exports = mongoose => { const schema = mongoose.Schema({ firstname: { type: String, required: true }, lastname: { type: String, required: true }, birthdate: { type: Date }, plan: { type: String, enum: ['free', 'pro', 'enterprise'] }, rating: { type: Number } }, { timestamps: true });
return mongoose.model('users', schema, 'users');};