28 lines
571 B
JavaScript
28 lines
571 B
JavaScript
module.exports = (sequelize, DataTypes) => {
|
|
const Cars = sequelize.define(
|
|
"Cars",
|
|
{
|
|
name: DataTypes.STRING,
|
|
year: DataTypes.INTEGER,
|
|
active: DataTypes.BOOLEAN,
|
|
brandId: {
|
|
type: DataTypes.INTEGER,
|
|
references: {
|
|
model: "Brands",
|
|
key: "id"
|
|
}
|
|
}
|
|
},
|
|
{}
|
|
);
|
|
|
|
Cars.associate = function(models) {
|
|
Cars.belongsTo(models.Brands, {
|
|
as: "Brand",
|
|
foreignKey: "brandId"
|
|
});
|
|
Cars.belongsToMany(models.Colors, { through: models.CarsColors });
|
|
};
|
|
|
|
return Cars;
|
|
};
|