sequelize-middleware/models/cars.js

29 lines
571 B
JavaScript
Raw Normal View History

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"
});
2020-02-13 22:36:14 +01:00
Cars.belongsToMany(models.Colors, { through: models.CarsColors });
};
return Cars;
};