forked from TuringCom/backend_challenge_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattributeValue.js
More file actions
executable file
·41 lines (38 loc) · 894 Bytes
/
Copy pathattributeValue.js
File metadata and controls
executable file
·41 lines (38 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = (sequelize, DataTypes) => {
const AttributeValue = sequelize.define(
'AttributeValue',
{
attribute_value_id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
attribute_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
value: {
type: DataTypes.STRING(100),
allowNull: false,
validate: {
notEmpty: true,
},
},
},
{
timestamps: false,
tableName: 'attribute_value',
}
);
AttributeValue.associate = ({ Attribute, Product }) => {
AttributeValue.belongsTo(Attribute, {
foreignKey: 'attribute_id',
as: 'attribute_type',
});
AttributeValue.belongsToMany(Product, {
through: 'ProductAttribute',
foreignKey: 'attribute_value_id',
});
};
return AttributeValue;
};