Created
January 8, 2016 21:45
-
-
Save thebergamo/e3215d3f9874e72e1906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = (sequelize, DataType) => { | |
let Category = sequelize.define('Category', { | |
name: { | |
type: DataType.STRING(100), | |
allowNull: false | |
}, | |
description: { | |
type: DataType.TEXT, | |
allowNull: false, | |
defaultValue: '' | |
}, | |
parentId: { | |
type: DataType.INTEGER, | |
allowNull: true, | |
references: { | |
model: 'Categories', | |
key: 'id' | |
} | |
}, | |
status: { | |
type: DataType.BOOLEAN, | |
allowNull: false, | |
defaultValue: false | |
} | |
}, { | |
classMethods: { | |
associate: (models) => { | |
Category.belongsTo(models.Category, { foreignKey: 'parentId' }); | |
Category.belongsToMany(models.Product, | |
{ through: 'ProductCategory' }); | |
} | |
} | |
}); | |
return Category; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = (sequelize, DataType) => { | |
let Product = sequelize.define('Product', { | |
name: { | |
type: DataType.STRING(100), | |
allowNull: false | |
}, | |
description: { | |
type: DataType.TEXT, | |
allowNull: false, | |
defaultValue: '' | |
}, | |
model: { | |
type: DataType.STRING(50), | |
allowNull: true | |
}, | |
upc: { | |
type: DataType.STRING(13), | |
allowNull: true | |
}, | |
price: { | |
type: DataType.DECIMAL(14, 2), | |
allowNull: false, | |
defaultValue: 0.00 | |
}, | |
status: { | |
type: DataType.BOOLEAN, | |
allowNull: false, | |
defaultValue: false | |
} | |
}, { | |
classMethods: { | |
associate: (models) => { | |
Product.belongsToMany(models.Category, | |
{ through: 'ProductCategory' }); | |
} | |
} | |
}); | |
return Product; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment