If there is no custom property, forestadmin detects many to many relationships. How should we manage this relationship when we use a custom property?
CREATE TABLE exercise_instruction (
exercise_id INT NOT NULL,
instruction_id INT NOT NULL,
rank INT NOT NULL DEFAULT 0,
CONSTRAINT fk_exercise FOREIGN KEY(exercise_id) REFERENCES exercises(id),
CONSTRAINT fk_instruction FOREIGN KEY(instruction_id) REFERENCES instructions(id)
);
// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const ExerciseInstruction = sequelize.define('exerciseInstruction', {
exerciseId: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
},
instructionId: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
},
rank: {
type: DataTypes.INTEGER,
defaultValue: 0,
allowNull: false,
},
}, {
tableName: 'exercise_instruction',
underscored: true,
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/reference-guide/relationships#adding-relationships.
ExerciseInstruction.associate = (models) => {
ExerciseInstruction.belongsTo(models.exercises, {
foreignKey: {
name: 'exerciseIdKey',
field: 'exercise_id',
},
as: 'exercise',
});
ExerciseInstruction.belongsTo(models.instructions, {
foreignKey: {
name: 'instructionIdKey',
field: 'instruction_id',
},
as: 'instruction',
});
};
return ExerciseInstruction;
};