Hi team,
I have some trouble with a many to many relationship.
I have a product.
I have colors.
I have a ProductColors through table.
But this table has a isDefault field.
I can’t find a way to set this value in the UI while creating a new color for the product table UI.
(error : Field ‘isDefault’ doesn’t have a default value)
Is there a way to set this value while creating an element on the other end of the relationship ?
Thank you for your help
ps : The code
Product Colors
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/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Products_Colors = sequelize.define(
"products_colors",
{
isDefault: {
type: DataTypes.BOOLEAN,
},
},
{
tableName: "products_colors",
timestamps: false,
}
);
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Products_Colors.associate = (models) => {
Products_Colors.belongsTo(models.product, {
onDelete: "CASCADE",
onUpdate: "CASCADE",
});
Products_Colors.belongsTo(models.color, {
onDelete: "CASCADE",
onUpdate: "CASCADE",
});
};
return Products_Colors;
};
Colors
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/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Color = sequelize.define(
"color",
{
name: {
type: DataTypes.STRING,
allowNull: false,
},
value: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
tableName: "color",
timestamps: false,
}
);
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Color.associate = (models) => {
Color.belongsToMany(models.product, {
through: "products_colors",
});
};
return Color;
};
Products
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/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Product = sequelize.define(
"product",
{
name: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
tableName: "product",
timestamps: false,
}
);
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Product.associate = (models) => {
Product.belongsToMany(models.color, {
through: "products_colors",
as: "Colors",
});
};
return Product;
};
`