28 lines
500 B
JavaScript
28 lines
500 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"
|
||
|
});
|
||
|
};
|
||
|
|
||
|
return Cars;
|
||
|
};
|